/** * Zips a file or a folder. If adding a folder, all its content will be added. */ public static File zip(File file) throws IOException { String zipFile = file.getAbsolutePath() + ZIP_EXT; return ZipBuilder.createZipFile(zipFile) .add(file).recursive().save() .toZipFile(); }
public static ZipBuilder createZipInMemory() { return new ZipBuilder(); }
@Test void testZipBuilderFileMemory() throws IOException { byte[] bytes = ZipBuilder.createZipInMemory() .add(new File(dataRoot, "sb.data")) .path("sbdata").comment("This is sb data file").save() .add(new File(dataRoot, "file")) .path("folder").comment("This is a folder and all its files").save() .add("text") .path("folder/txt").save() .addFolder("folder2") .add("txet") .path("folder2/txt2").save() .toBytes();
@Test void testZipEmptyFolder() throws IOException { byte[] bytes = ZipBuilder .createZipInMemory() .addFolder("myEmptyFolder") .toBytes(); File tempDir = FileUtil.createTempDirectory(); tempDir.deleteOnExit(); File zipFile = new File(tempDir, "test.zip"); FileUtil.writeBytes(zipFile, bytes); // read zip List<String> entries = ZipUtil.listZip(zipFile); assertEquals(1, entries.size()); assertEquals("myEmptyFolder/", entries.get(0)); }
/** * Zips a file or a folder. If adding a folder, all its content will be added. */ public static File zip(final File file) throws IOException { String zipFile = file.getAbsolutePath() + ZIP_EXT; return ZipBuilder.createZipFile(zipFile) .add(file).recursive().save() .toZipFile(); }
public static ZipBuilder createZipFile(File zipFile) throws IOException { return new ZipBuilder(zipFile); } public static ZipBuilder createZipFile(String zipFile) throws IOException {
@Test void testZipBuilderFile() throws IOException { File zipFile = new File(dataRoot, "test.zip"); ZipBuilder.createZipFile(zipFile) .add(new File(dataRoot, "sb.data")) .path("sbdata").comment("This is sb data file").save() .add(new File(dataRoot, "file")) .path("folder").comment("This is a folder and all its files").save() .toZipFile(); assertTrue(zipFile.exists()); ZipUtil.unzip(zipFile, new File(dataRoot), "sbda*"); assertTrue(new File(dataRoot, "sbdata").exists()); assertFalse(new File(dataRoot, "folder").exists()); ZipUtil.unzip(zipFile, new File(dataRoot)); assertTrue(new File(dataRoot, "sbdata").exists()); assertTrue(new File(dataRoot, "folder").exists()); assertTrue(new File(new File(dataRoot, "folder"), "a.png").exists()); // cleanup FileUtil.delete(new File(dataRoot, "sbdata")); FileUtil.deleteDir(new File(dataRoot, "folder")); FileUtil.delete(zipFile); }
public static ZipBuilder createZipFile(final File zipFile) throws IOException { return new ZipBuilder(zipFile); } public static ZipBuilder createZipFile(final String zipFile) throws IOException {
/** * Zips a file or a folder. If adding a folder, all its content will be added. */ public static File zip(final File file) throws IOException { String zipFile = file.getAbsolutePath() + ZIP_EXT; return ZipBuilder.createZipFile(zipFile) .add(file).recursive().save() .toZipFile(); }
public static ZipBuilder createZipInMemory() { return new ZipBuilder(); }
public static ZipBuilder createZipFile(String zipFile) throws IOException { return new ZipBuilder(new File(zipFile)); }
public static ZipBuilder createZipFile(final String zipFile) throws IOException { return new ZipBuilder(new File(zipFile)); }
public static ZipBuilder createZipFile(final File zipFile) throws IOException { return new ZipBuilder(zipFile); } public static ZipBuilder createZipFile(final String zipFile) throws IOException {
public static ZipBuilder createZipInMemory() { return new ZipBuilder(); }
public static ZipBuilder createZipFile(final String zipFile) throws IOException { return new ZipBuilder(new File(zipFile)); }