/** * Compresses a file into gzip archive. */ public static File gzip(String fileName) throws IOException { return gzip(new File(fileName)); }
/** * Decompress gzip archive. */ public static File ungzip(String file) throws IOException { return ungzip(new File(file)); }
/** * Extracts zip file content to the target directory. * @see #unzip(java.io.File, java.io.File, String...) */ public static void unzip(String zipFile, String destDir, String... patterns) throws IOException { unzip(new File(zipFile), new File(destDir), patterns); }
@Test void testGzip() throws IOException { ZipUtil.gzip(new File(dataRoot, "sb.data")); File gzipFile = new File(dataRoot, "sb.data.gz"); assertTrue(gzipFile.exists()); FileUtil.move(gzipFile, new File(dataRoot, "sb2.data.gz")); ZipUtil.ungzip(new File(dataRoot, "sb2.data.gz")); File data = new File(dataRoot, "sb2.data"); assertTrue(data.exists()); byte[] data2Bytes = FileUtil.readBytes(data); byte[] data1Bytes = FileUtil.readBytes(new File(dataRoot, "sb.data")); assertTrue(Arrays.equals(data1Bytes, data2Bytes)); // cleanup FileUtil.delete(new File(dataRoot, "sb2.data")); FileUtil.delete(new File(dataRoot, "sb2.data.gz")); }
/** * Stores the content into the ZIP. */ public ZipBuilder save() throws IOException { ZipUtil.addToZip(zos, file, path, comment, recursive); return ZipBuilder.this; } }
/** * Zips a file or a folder. * @see #zip(java.io.File) */ public static File zip(String file) throws IOException { return zip(new File(file)); }
/** * Compresses a file into zlib archive. */ public static File zlib(String file) throws IOException { return zlib(new File(file)); }
public ZipBuilder addFolder(String folderName) throws IOException { ZipUtil.addFolderToZip(zos, folderName, null); return this; }
/** * Stores the content into the ZIP. */ public ZipBuilder save() throws IOException { ZipUtil.addToZip(zos, bytes, path, comment); return ZipBuilder.this; } }
/** * Zips a file or a folder. * @see #zip(java.io.File) */ public static File zip(final String file) throws IOException { return zip(new File(file)); }
/** * Compresses a file into zlib archive. */ public static File zlib(final String file) throws IOException { return zlib(new File(file)); }
close(zip);
public ZipBuilder addFolder(final String folderName) throws IOException { ZipUtil.addFolderToZip(zos, folderName, null); return this; }
/** * Compresses a file into gzip archive. */ public static File gzip(final String fileName) throws IOException { return gzip(new File(fileName)); }
/** * Decompress gzip archive. */ public static File ungzip(final String file) throws IOException { return ungzip(new File(file)); }
/** * Stores the content into the ZIP. */ public ZipBuilder save() throws IOException { ZipUtil.addToZip(zos, bytes, path, comment); return ZipBuilder.this; } }
/** * Extracts zip file content to the target directory. * @see #unzip(java.io.File, java.io.File, String...) */ public static void unzip(final String zipFile, final String destDir, final String... patterns) throws IOException { unzip(new File(zipFile), new File(destDir), patterns); }
@Test void testZip() throws IOException { ZipUtil.zip(new File(dataRoot, "sb.data")); File zipFile = new File(dataRoot, "sb.data.zip"); assertTrue(zipFile.exists()); // cleanup FileUtil.delete(zipFile); ZipUtil.zip(new File(dataRoot, "file")); zipFile = new File(dataRoot, "file.zip"); assertTrue(zipFile.exists()); // cleanup FileUtil.delete(zipFile); }
@Test void testZlib() throws IOException { ZipUtil.zlib(new File(dataRoot, "sb.data")); File zlibFile = new File(dataRoot, "sb.data.zlib"); assertTrue(zlibFile.exists()); // cleanup FileUtil.delete(zlibFile); }