org.zeroturnaround.zip.ZipUtil类的使用及代码示例

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

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

ZipUtil介绍

[英]ZIP file manipulation utilities.
[中]

代码示例

代码示例来源: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

/**
 * Unpacks a ZIP file to the given directory.
 * <p>
 * The output directory must not be a file.
 *
 * @param zip
 *          input ZIP file.
 * @param outputDir
 *          output directory (created automatically if not found).
 */
public static void unpack(File zip, final File outputDir) {
 unpack(zip, outputDir, IdentityNameMapper.INSTANCE);
}

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

/**
 * Unpacks a single file from a ZIP archive to a file.
 *
 * @param zip
 *          ZIP file.
 * @param name
 *          entry name.
 * @param file
 *          target file to be created or overwritten.
 * @return <code>true</code> if the entry was found and unpacked,
 *         <code>false</code> if the entry was not found.
 */
public static boolean unpackEntry(File zip, String name, File file) {
 return unpackEntry(zip, name, file, null);
}

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

final Set<String> dirNames = filterDirEntries(zip, ignoredEntries);
iterate(zip, new ZipEntryCallback() {
 public void process(InputStream in, ZipEntry zipEntry) throws IOException {
  String entryName = zipEntry.getName();

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

final Map<String, ZipEntrySource> entryByPath = entriesByPath(entries);
try {
 final ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(destZip)));
  iterate(zip, new ZipEntryCallback() {
   public void process(InputStream in, ZipEntry zipEntry) throws IOException {
    if (names.add(zipEntry.getName())) {
   addEntry(zipEntrySource, out);

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

final Map<String, ZipEntrySource> entryByPath = entriesByPath(entries);
final int entryCount = entryByPath.size();
try {
 try {
  final Set<String> names = new HashSet<String>();
  iterate(zip, new ZipEntryCallback() {
   public void process(InputStream in, ZipEntry zipEntry) throws IOException {
    if (names.add(zipEntry.getName())) {

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

ZipUtil.unpack(jar, jarDir);
} else {
  PackrFileUtils.delete(jar);
  ZipUtil.pack(jarDir, jar);
  FileUtils.deleteDirectory(jarDir);

代码示例来源: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;
  }
}

代码示例来源:origin: fgl27/isu

ZipUtil.pack(new File(sdcard + "/iSu_Logs/tmpziplog"), new File(zip_file));
ZipUtil.unpackEntry(new File(zip_file), "logcat.txt", new File(tmplogcat));
if (compareFiles(logcat, tmplogcat, true, mContext)) {
  Log.d(TAG, "ziped logcat.txt is ok");

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

/**
 * See {@link #iterate(InputStream, ZipEntryCallback, Charset)}. This method
 * is a shorthand for a version where no Charset is specified.
 *
 * @param is
 *          input ZIP stream (it will not be closed automatically).
 * @param action
 *          action to be called for each entry.
 *
 * @see ZipEntryCallback
 * @see #iterate(File, ZipEntryCallback)
 */
public static void iterate(InputStream is, ZipEntryCallback action) {
 iterate(is, action, null);
}

代码示例来源:origin: PlayPen/playpen-core

public P3Package readPackage(File file) throws PackageException {
  try {
    if (!ZipUtil.containsEntry(file, "package.json")) {
      throw new PackageException("No package schema found");
    }
    byte[] schemaBytes = ZipUtil.unpackEntry(file, "package.json");
    String schemaString = new String(schemaBytes);
    JSONObject schema = new JSONObject(schemaString);
    P3Package p3 = readSchema(schema);
    p3.setLocalPath(file.getPath());
    return p3;
  }
  catch(JSONException e) {
    throw new PackageException("Invalid package schema", e);
  }
}

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

public boolean act(File tmpFile) {
  removeEntry(zip, path, tmpFile);
  return true;
 }
});

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

@Signature
public void remove(Environment env, Memory path) {
  if (path.isTraversable()) {
    ForeachIterator iterator = path.getNewIterator(env);
    List<String> paths = new ArrayList<>();
    while (iterator.next()) {
      String value = iterator.getValue().toString();
      paths.add(value);
    }
    ZipUtil.removeEntries(zipFile, paths.toArray(new String[paths.size()]));
  } else {
    ZipUtil.removeEntry(zipFile, path.toString());
  }
}

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

/**
 * Alias to ZipUtil.containsEntry()
 *
 * @param name
 *          entry to check existence of
 * @return true if zip archive we're processing contains entry by given name, false otherwise
 */
public boolean containsEntry(String name) {
 if (src == null) {
  throw new IllegalStateException("Source is not given");
 }
 return ZipUtil.containsEntry(src, name);
}

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

System.out.println("  # Unpacking '" + file.getPath() + "' ...");
ZipUtil.unpack(file, fileNoExt);
PackrFileUtils.delete(file);
ZipUtil.pack(fileNoExt, file);
FileUtils.deleteDirectory(fileNoExt);

代码示例来源: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: zeroturnaround/zt-zip

/**
 * Reads the given ZIP file and executes the given action for each entry.
 * <p>
 * For each entry the corresponding input stream is also passed to the action. If you want to stop the loop
 * then throw a ZipBreakException.
 *
 * @param zip
 *          input ZIP file.
 * @param action
 *          action to be called for each entry.
 *
 * @see ZipEntryCallback
 * @see #iterate(File, ZipInfoCallback)
 */
public static void iterate(File zip, ZipEntryCallback action) {
 iterate(zip, action, null);
}

代码示例来源:origin: PlayPen/playpen-core

if(!ZipUtil.containsEntry(jarFile, "plugin.json")) {
  log.warn("Jar " + jarFile.getPath() + " does not contain a plugin.json");
  continue;
byte[] schemaBytes = ZipUtil.unpackEntry(jarFile, "plugin.json");
String schemaString = new String(schemaBytes);
if (ZipUtil.containsEntry(jarFile, "config.json")) {
  schema.getFiles().add("config.json");
  if (!ZipUtil.containsEntry(jarFile, filename)) {
    log.error("Plugin file " + filename + " for " + schema.getId() + " doesn't exist in jar");
    return false;
  byte[] fileBytes = null;
  if (!pluginFile.exists()) {
    fileBytes = ZipUtil.unpackEntry(jarFile, filename);
    try {
      Files.write(pluginFile.toPath(), fileBytes);
if(ZipUtil.containsEntry(jarFile, "config.json")) {
  File configFile = Paths.get(pluginDir.getPath(), "config.json").toFile();
  byte[] configBytes = null;

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

public boolean act(File tmpFile) {
  removeEntry(zip, path, tmpFile);
  return true;
 }
});

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

@Signature
public boolean has(String path) {
  return ZipUtil.containsEntry(zipFile, path);
}

相关文章