org.zeroturnaround.zip.ZipUtil.pack()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(300)

本文整理了Java中org.zeroturnaround.zip.ZipUtil.pack()方法的一些代码示例,展示了ZipUtil.pack()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipUtil.pack()方法的具体详情如下:
包路径:org.zeroturnaround.zip.ZipUtil
类名称:ZipUtil
方法名:pack

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

  1. /**
  2. * Compresses the given directory and all its sub-directories into a ZIP file.
  3. * <p>
  4. * The ZIP file must not be a directory and its parent directory must exist.
  5. * Will not include the root directory name in the archive.
  6. *
  7. * @param rootDir
  8. * root directory.
  9. * @param zip
  10. * ZIP file that will be created or overwritten.
  11. */
  12. public static void pack(File rootDir, File zip) {
  13. pack(rootDir, zip, DEFAULT_COMPRESSION_LEVEL);
  14. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given directory and all of its sub-directories into the passed in
  3. * stream. It is the responsibility of the caller to close the passed in
  4. * stream properly.
  5. *
  6. * @param sourceDir
  7. * root directory.
  8. * @param os
  9. * output stream (will be buffered in this method).
  10. *
  11. * @since 1.10
  12. */
  13. public static void pack(File sourceDir, OutputStream os) {
  14. pack(sourceDir, os, IdentityNameMapper.INSTANCE, DEFAULT_COMPRESSION_LEVEL);
  15. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given directory and all of its sub-directories into the passed in
  3. * stream. It is the responsibility of the caller to close the passed in
  4. * stream properly.
  5. *
  6. * @param sourceDir
  7. * root directory.
  8. * @param os
  9. * output stream (will be buffered in this method).
  10. * @param compressionLevel
  11. * compression level
  12. *
  13. * @since 1.10
  14. */
  15. public static void pack(File sourceDir, OutputStream os, int compressionLevel) {
  16. pack(sourceDir, os, IdentityNameMapper.INSTANCE, compressionLevel);
  17. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given directory and all of its sub-directories into the passed in
  3. * stream. It is the responsibility of the caller to close the passed in
  4. * stream properly.
  5. *
  6. * @param sourceDir
  7. * root directory.
  8. * @param os
  9. * output stream (will be buffered in this method).
  10. * @param mapper
  11. * call-back for renaming the entries.
  12. *
  13. * @since 1.10
  14. */
  15. public static void pack(File sourceDir, OutputStream os, NameMapper mapper) {
  16. pack(sourceDir, os, mapper, DEFAULT_COMPRESSION_LEVEL);
  17. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given directory and all its sub-directories into a ZIP file.
  3. * <p>
  4. * The ZIP file must not be a directory and its parent directory must exist.
  5. *
  6. * @param sourceDir
  7. * root directory.
  8. * @param targetZip
  9. * ZIP file that will be created or overwritten.
  10. * @param mapper
  11. * call-back for renaming the entries.
  12. */
  13. public static void pack(File sourceDir, File targetZip, NameMapper mapper) {
  14. pack(sourceDir, targetZip, mapper, DEFAULT_COMPRESSION_LEVEL);
  15. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given directory and all its sub-directories into a ZIP file.
  3. * <p>
  4. * The ZIP file must not be a directory and its parent directory must exist.
  5. * Will not include the root directory name in the archive.
  6. *
  7. * @param rootDir
  8. * root directory.
  9. * @param zip
  10. * ZIP file that will be created or overwritten.
  11. * @param compressionLevel
  12. * compression level
  13. */
  14. public static void pack(File rootDir, File zip, int compressionLevel) {
  15. pack(rootDir, zip, IdentityNameMapper.INSTANCE, compressionLevel);
  16. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given directory and all its sub-directories into a ZIP file.
  3. * <p>
  4. * The ZIP file must not be a directory and its parent directory must exist.
  5. * Will not include the root directory name in the archive.
  6. *
  7. * @param sourceDir
  8. * root directory.
  9. * @param targetZipFile
  10. * ZIP file that will be created or overwritten.
  11. * @param preserveRoot
  12. * true if the resulted archive should have the top directory entry
  13. */
  14. public static void pack(final File sourceDir, final File targetZipFile, final boolean preserveRoot) {
  15. if (preserveRoot) {
  16. final String parentName = sourceDir.getName();
  17. pack(sourceDir, targetZipFile, new NameMapper() {
  18. public String map(String name) {
  19. return parentName + PATH_SEPARATOR + name;
  20. }
  21. });
  22. }
  23. else {
  24. pack(sourceDir, targetZipFile);
  25. }
  26. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given entries into an output stream.
  3. *
  4. * @param entries
  5. * ZIP entries added.
  6. * @param os
  7. * output stream for the new ZIP (does not have to be buffered)
  8. *
  9. * @since 1.9
  10. */
  11. public static void pack(ZipEntrySource[] entries, OutputStream os) {
  12. if (log.isDebugEnabled()) {
  13. log.debug("Creating stream from {}.", Arrays.asList(entries));
  14. }
  15. pack(entries, os, false);
  16. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses the given entries into a new ZIP file.
  3. *
  4. * @param entries
  5. * ZIP entries added.
  6. * @param zip
  7. * new ZIP file created.
  8. */
  9. public static void pack(ZipEntrySource[] entries, File zip) {
  10. if (log.isDebugEnabled()) {
  11. log.debug("Creating '{}' from {}.", zip, Arrays.asList(entries));
  12. }
  13. OutputStream out = null;
  14. try {
  15. out = new BufferedOutputStream(new FileOutputStream(zip));
  16. pack(entries, out, true);
  17. }
  18. catch (IOException e) {
  19. throw ZipExceptionUtil.rethrow(e);
  20. }
  21. finally {
  22. IOUtils.closeQuietly(out);
  23. }
  24. }

代码示例来源:origin: libgdx/packr

  1. PackrFileUtils.delete(jar);
  2. ZipUtil.pack(jarDir, jar);
  3. FileUtils.deleteDirectory(jarDir);

代码示例来源:origin: jphp-group/jphp

  1. @Signature
  2. public void addDirectory(Environment env, File path, int compressLevel, @Nullable Invoker invoker) {
  3. ZipUtil.pack(path, zipFile, invokerToNameMapper(invoker), compressLevel);
  4. }

代码示例来源:origin: zeroturnaround/zt-zip

  1. out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetZip)));
  2. out.setLevel(compressionLevel);
  3. pack(sourceDir, out, mapper, "", true);

代码示例来源:origin: zeroturnaround/zt-zip

  1. out = new ZipOutputStream(new BufferedOutputStream(os));
  2. out.setLevel(compressionLevel);
  3. pack(sourceDir, out, mapper, "", true);

代码示例来源:origin: zeroturnaround/zt-zip

  1. pack(file, out, mapper, path, false);

代码示例来源:origin: libgdx/packr

  1. PackrFileUtils.delete(file);
  2. ZipUtil.pack(fileNoExt, file);
  3. FileUtils.deleteDirectory(fileNoExt);

代码示例来源:origin: zeroturnaround/zt-zip

  1. /**
  2. * Compresses a given directory in its own location.
  3. * <p>
  4. * A ZIP file will be first created with a temporary name. After the
  5. * compressing the directory will be deleted and the ZIP file will be renamed
  6. * as the original directory.
  7. *
  8. * @param dir
  9. * input directory as well as the target ZIP file.
  10. * @param compressionLevel
  11. * compression level
  12. *
  13. * @see #pack(File, File)
  14. */
  15. public static void unexplode(File dir, int compressionLevel) {
  16. try {
  17. // Find a new unique name is the same directory
  18. File zip = FileUtils.getTempFileFor(dir);
  19. // Pack it
  20. pack(dir, zip, compressionLevel);
  21. // Delete the directory
  22. FileUtils.deleteDirectory(dir);
  23. // Rename the archive
  24. FileUtils.moveFile(zip, dir);
  25. }
  26. catch (IOException e) {
  27. throw ZipExceptionUtil.rethrow(e);
  28. }
  29. }

代码示例来源:origin: io.github.aktoluna/slnarch-common

  1. public static void zipDirectory(File directoryPath, File outputPath, int compressLevel) {
  2. ZipUtil.pack(directoryPath, outputPath, compressLevel);
  3. }
  4. }

代码示例来源:origin: com.infotel.seleniumRobot/core

  1. public static void zipFolder(final File folder, final File destZipFile) {
  2. try {
  3. File tempZip = File.createTempFile(destZipFile.getName(), ".zip");
  4. tempZip.deleteOnExit();
  5. ZipUtil.pack(folder, tempZip);
  6. FileUtils.copyFile(tempZip, destZipFile);
  7. } catch (IOException e) {
  8. logger.error("cannot create zip file", e);
  9. }
  10. }
  11. }

代码示例来源:origin: Microsoft/azure-maven-plugins

  1. protected File getZipFile() {
  2. final File zipFile = new File(stagingDirectoryPath + ".zip");
  3. final File stagingDirectory = new File(stagingDirectoryPath);
  4. ZipUtil.pack(stagingDirectory, zipFile);
  5. ZipUtil.removeEntry(zipFile, LOCAL_SETTINGS_FILE);
  6. return zipFile;
  7. }
  8. }

代码示例来源:origin: com.microsoft.azure/azure-maven-plugin-lib

  1. protected File getZipFile() {
  2. final File zipFile = new File(stagingDirectoryPath + ".zip");
  3. final File stagingDirectory = new File(stagingDirectoryPath);
  4. ZipUtil.pack(stagingDirectory, zipFile);
  5. ZipUtil.removeEntry(zipFile, LOCAL_SETTINGS_FILE);
  6. return zipFile;
  7. }
  8. }

相关文章