/** * Compresses the given directory and all its sub-directories into a ZIP file. * <p> * The ZIP file must not be a directory and its parent directory must exist. * Will not include the root directory name in the archive. * * @param rootDir * root directory. * @param zip * ZIP file that will be created or overwritten. */ public static void pack(File rootDir, File zip) { pack(rootDir, zip, DEFAULT_COMPRESSION_LEVEL); }
/** * Compresses the given directory and all of its sub-directories into the passed in * stream. It is the responsibility of the caller to close the passed in * stream properly. * * @param sourceDir * root directory. * @param os * output stream (will be buffered in this method). * * @since 1.10 */ public static void pack(File sourceDir, OutputStream os) { pack(sourceDir, os, IdentityNameMapper.INSTANCE, DEFAULT_COMPRESSION_LEVEL); }
/** * Compresses the given directory and all of its sub-directories into the passed in * stream. It is the responsibility of the caller to close the passed in * stream properly. * * @param sourceDir * root directory. * @param os * output stream (will be buffered in this method). * @param compressionLevel * compression level * * @since 1.10 */ public static void pack(File sourceDir, OutputStream os, int compressionLevel) { pack(sourceDir, os, IdentityNameMapper.INSTANCE, compressionLevel); }
/** * Compresses the given directory and all of its sub-directories into the passed in * stream. It is the responsibility of the caller to close the passed in * stream properly. * * @param sourceDir * root directory. * @param os * output stream (will be buffered in this method). * @param mapper * call-back for renaming the entries. * * @since 1.10 */ public static void pack(File sourceDir, OutputStream os, NameMapper mapper) { pack(sourceDir, os, mapper, DEFAULT_COMPRESSION_LEVEL); }
/** * Compresses the given directory and all its sub-directories into a ZIP file. * <p> * The ZIP file must not be a directory and its parent directory must exist. * * @param sourceDir * root directory. * @param targetZip * ZIP file that will be created or overwritten. * @param mapper * call-back for renaming the entries. */ public static void pack(File sourceDir, File targetZip, NameMapper mapper) { pack(sourceDir, targetZip, mapper, DEFAULT_COMPRESSION_LEVEL); }
/** * Compresses the given directory and all its sub-directories into a ZIP file. * <p> * The ZIP file must not be a directory and its parent directory must exist. * Will not include the root directory name in the archive. * * @param rootDir * root directory. * @param zip * ZIP file that will be created or overwritten. * @param compressionLevel * compression level */ public static void pack(File rootDir, File zip, int compressionLevel) { pack(rootDir, zip, IdentityNameMapper.INSTANCE, compressionLevel); }
/** * Compresses the given directory and all its sub-directories into a ZIP file. * <p> * The ZIP file must not be a directory and its parent directory must exist. * Will not include the root directory name in the archive. * * @param sourceDir * root directory. * @param targetZipFile * ZIP file that will be created or overwritten. * @param preserveRoot * true if the resulted archive should have the top directory entry */ public static void pack(final File sourceDir, final File targetZipFile, final boolean preserveRoot) { if (preserveRoot) { final String parentName = sourceDir.getName(); pack(sourceDir, targetZipFile, new NameMapper() { public String map(String name) { return parentName + PATH_SEPARATOR + name; } }); } else { pack(sourceDir, targetZipFile); } }
/** * Compresses the given entries into an output stream. * * @param entries * ZIP entries added. * @param os * output stream for the new ZIP (does not have to be buffered) * * @since 1.9 */ public static void pack(ZipEntrySource[] entries, OutputStream os) { if (log.isDebugEnabled()) { log.debug("Creating stream from {}.", Arrays.asList(entries)); } pack(entries, os, false); }
/** * Compresses the given entries into a new ZIP file. * * @param entries * ZIP entries added. * @param zip * new ZIP file created. */ public static void pack(ZipEntrySource[] entries, File zip) { if (log.isDebugEnabled()) { log.debug("Creating '{}' from {}.", zip, Arrays.asList(entries)); } OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(zip)); pack(entries, out, true); } catch (IOException e) { throw ZipExceptionUtil.rethrow(e); } finally { IOUtils.closeQuietly(out); } }
PackrFileUtils.delete(jar); ZipUtil.pack(jarDir, jar); FileUtils.deleteDirectory(jarDir);
@Signature public void addDirectory(Environment env, File path, int compressLevel, @Nullable Invoker invoker) { ZipUtil.pack(path, zipFile, invokerToNameMapper(invoker), compressLevel); }
out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetZip))); out.setLevel(compressionLevel); pack(sourceDir, out, mapper, "", true);
out = new ZipOutputStream(new BufferedOutputStream(os)); out.setLevel(compressionLevel); pack(sourceDir, out, mapper, "", true);
pack(file, out, mapper, path, false);
PackrFileUtils.delete(file); ZipUtil.pack(fileNoExt, file); FileUtils.deleteDirectory(fileNoExt);
/** * Compresses a given directory in its own location. * <p> * A ZIP file will be first created with a temporary name. After the * compressing the directory will be deleted and the ZIP file will be renamed * as the original directory. * * @param dir * input directory as well as the target ZIP file. * @param compressionLevel * compression level * * @see #pack(File, File) */ public static void unexplode(File dir, int compressionLevel) { try { // Find a new unique name is the same directory File zip = FileUtils.getTempFileFor(dir); // Pack it pack(dir, zip, compressionLevel); // Delete the directory FileUtils.deleteDirectory(dir); // Rename the archive FileUtils.moveFile(zip, dir); } catch (IOException e) { throw ZipExceptionUtil.rethrow(e); } }
public static void zipDirectory(File directoryPath, File outputPath, int compressLevel) { ZipUtil.pack(directoryPath, outputPath, compressLevel); } }
public static void zipFolder(final File folder, final File destZipFile) { try { File tempZip = File.createTempFile(destZipFile.getName(), ".zip"); tempZip.deleteOnExit(); ZipUtil.pack(folder, tempZip); FileUtils.copyFile(tempZip, destZipFile); } catch (IOException e) { logger.error("cannot create zip file", e); } } }
protected File getZipFile() { final File zipFile = new File(stagingDirectoryPath + ".zip"); final File stagingDirectory = new File(stagingDirectoryPath); ZipUtil.pack(stagingDirectory, zipFile); ZipUtil.removeEntry(zipFile, LOCAL_SETTINGS_FILE); return zipFile; } }
protected File getZipFile() { final File zipFile = new File(stagingDirectoryPath + ".zip"); final File stagingDirectory = new File(stagingDirectoryPath); ZipUtil.pack(stagingDirectory, zipFile); ZipUtil.removeEntry(zipFile, LOCAL_SETTINGS_FILE); return zipFile; } }