本文整理了Java中org.zeroturnaround.zip.ZipUtil.pack()
方法的一些代码示例,展示了ZipUtil.pack()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipUtil.pack()
方法的具体详情如下:
包路径:org.zeroturnaround.zip.ZipUtil
类名称:ZipUtil
方法名:pack
[英]Compresses the given directory and all its sub-directories into a ZIP file.
The ZIP file must not be a directory and its parent directory must exist. Will not include the root directory name in the archive.
[中]将给定目录及其所有子目录压缩为ZIP文件。
ZIP文件不能是目录,其父目录必须存在。将不在存档中包含根目录名。
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
}
代码示例来源:origin: libgdx/packr
PackrFileUtils.delete(jar);
ZipUtil.pack(jarDir, jar);
FileUtils.deleteDirectory(jarDir);
代码示例来源:origin: jphp-group/jphp
@Signature
public void addDirectory(Environment env, File path, int compressLevel, @Nullable Invoker invoker) {
ZipUtil.pack(path, zipFile, invokerToNameMapper(invoker), compressLevel);
}
代码示例来源:origin: zeroturnaround/zt-zip
out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetZip)));
out.setLevel(compressionLevel);
pack(sourceDir, out, mapper, "", true);
代码示例来源:origin: zeroturnaround/zt-zip
out = new ZipOutputStream(new BufferedOutputStream(os));
out.setLevel(compressionLevel);
pack(sourceDir, out, mapper, "", true);
代码示例来源:origin: zeroturnaround/zt-zip
pack(file, out, mapper, path, false);
代码示例来源:origin: libgdx/packr
PackrFileUtils.delete(file);
ZipUtil.pack(fileNoExt, file);
FileUtils.deleteDirectory(fileNoExt);
代码示例来源:origin: zeroturnaround/zt-zip
/**
* 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);
}
}
代码示例来源:origin: io.github.aktoluna/slnarch-common
public static void zipDirectory(File directoryPath, File outputPath, int compressLevel) {
ZipUtil.pack(directoryPath, outputPath, compressLevel);
}
}
代码示例来源:origin: com.infotel.seleniumRobot/core
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);
}
}
}
代码示例来源:origin: Microsoft/azure-maven-plugins
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;
}
}
代码示例来源:origin: com.microsoft.azure/azure-maven-plugin-lib
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;
}
}
内容来源于网络,如有侵权,请联系作者删除!