Git Product home page Git Product logo

zt-zip's Introduction

ZIP - convenience methods

Quick Overview

The project was started and coded by Rein Raudjärv when he needed to process a large set of large ZIP archives for LiveRebel internals. Soon after we started using the utility in other projects because of the ease of use and it just worked.

The project is built using java.util.zip.* packages for stream based access. Most convenience methods for filesystem usage is also supported.

Installation

Maven Central

The project artifacts are available in Maven Central Repository. To include it in your maven project then you have to specify the dependency.

...
<dependency>
    <groupId>org.zeroturnaround</groupId>
    <artifactId>zt-zip</artifactId>
    <version>1.17</version>
    <type>jar</type>
</dependency>
...

Notice that 1.8 is the last Java 1.4 compatible release. Since then Java 1.5 is required.

If you are using with ProGuard, please add the following configuration

-dontwarn org.slf4j.**

Background

We had the following functional requirements:

  1. pack and unpack directories recursively
  2. include/exclude entries
  3. rename entries
  4. packing/unpacking in place - ZIP becomes directory and vice versa
  5. iterate through ZIP entries
  6. add or replace entries from files or byte arrays
  7. transform ZIP entries
  8. compare two archives - compare all entries ignoring time stamps

and these non-functional requirements:

  1. use existing APIs as much as possible
  2. be simple to use
  3. be effective to use - do not traverse an entire ZIP file if only a single entry is needed
  4. be safe to use - do not enable user to leave streams open and keep files locked
  5. do not declare exceptions
  6. be compatible with Java 1.5

Examples

The examples don't include all the possible ways how to use the library but will give an overview. When you see a method that is useful but doesn't necessarily solve your use case then just head over to ZipUtil.class file and see the sibling methods that are named the same but arguments might be different.

Unpacking

Check if an entry exists in a ZIP archive

boolean exists = ZipUtil.containsEntry(new File("/tmp/demo.zip"), "foo.txt");

Extract an entry from a ZIP archive into a byte array

byte[] bytes = ZipUtil.unpackEntry(new File("/tmp/demo.zip"), "foo.txt");

Extract an entry from a ZIP archive with a specific Charset into a byte array

byte[] bytes = ZipUtil.unpackEntry(new File("/tmp/demo.zip"), "foo.txt", Charset.forName("IBM437"));

Extract an entry from a ZIP archive into file system

ZipUtil.unpackEntry(new File("/tmp/demo.zip"), "foo.txt", new File("/tmp/bar.txt"));

Extract a ZIP archive

ZipUtil.unpack(new File("/tmp/demo.zip"), new File("/tmp/demo"));

Extract a ZIP archive which becomes a directory

ZipUtil.explode(new File("/tmp/demo.zip"));

Extract a directory from a ZIP archive including the directory name

ZipUtil.unpack(new File("/tmp/demo.zip"), new File("/tmp/demo"), new NameMapper() {
  public String map(String name) {
    return name.startsWith("doc/") ? name : null;
  }
});

Extract a directory from a ZIP archive excluding the directory name

final String prefix = "doc/"; 
ZipUtil.unpack(new File("/tmp/demo.zip"), new File("/tmp/demo"), new NameMapper() {
  public String map(String name) {
    return name.startsWith(prefix) ? name.substring(prefix.length()) : name;
  }
});

Extract files from a ZIP archive that match a name pattern

ZipUtil.unpack(new File("/tmp/demo.zip"), new File("/tmp/demo"), new NameMapper() {
  public String map(String name) {
    if (name.contains("/doc")) {
      return name;
    }
    else {
      // returning null from the map method will disregard the entry
      return null;
    }
  }
});

Print .class entry names in a ZIP archive

ZipUtil.iterate(new File("/tmp/demo.zip"), new ZipInfoCallback() {
  public void process(ZipEntry zipEntry) throws IOException {
    if (zipEntry.getName().endsWith(".class"))
      System.out.println("Found " + zipEntry.getName());
  }
});

Print .txt entries in a ZIP archive (uses IoUtils from Commons IO)

ZipUtil.iterate(new File("/tmp/demo.zip"), new ZipEntryCallback() {
  public void process(InputStream in, ZipEntry zipEntry) throws IOException {
    if (zipEntry.getName().endsWith(".txt")) {
      System.out.println("Found " + zipEntry.getName());
      IOUtils.copy(in, System.out);
    }
  }
});

Packing

Compress a directory into a ZIP archive

ZipUtil.pack(new File("/tmp/demo"), new File("/tmp/demo.zip"));

Compress a directory which becomes a ZIP archive

ZipUtil.unexplode(new File("/tmp/demo.zip"));

Compress a directory into a ZIP archive with a parent directory

ZipUtil.pack(new File("/tmp/demo"), new File("/tmp/demo.zip"), new NameMapper() {
  public String map(String name) {
    return "foo/" + name;
  }
});

Compress a file into a ZIP archive

ZipUtil.packEntry(new File("/tmp/demo.txt"), new File("/tmp/demo.zip"));

Add an entry from file to a ZIP archive

ZipUtil.addEntry(new File("/tmp/demo.zip"), "doc/readme.txt", new File("f/tmp/oo.txt"), new File("/tmp/new.zip"));

Add an entry from byte array to a ZIP archive

ZipUtil.addEntry(new File("/tmp/demo.zip"), "doc/readme.txt", "bar".getBytes(), new File("/tmp/new.zip"));

Add an entry from file and from byte array to a ZIP archive

ZipEntrySource[] entries = new ZipEntrySource[] {
    new FileSource("doc/readme.txt", new File("foo.txt")),
    new ByteSource("sample.txt", "bar".getBytes())
};
ZipUtil.addEntries(new File("/tmp/demo.zip"), entries, new File("/tmp/new.zip"));

Add an entry from file and from byte array to a output stream

ZipEntrySource[] entries = new ZipEntrySource[] {
    new FileSource("doc/readme.txt", new File("foo.txt")),
    new ByteSource("sample.txt", "bar".getBytes())
};
OutputStream out = null;
try {
  out = new BufferedOutputStream(new FileOutputStream(new File("/tmp/new.zip")));
  ZipUtil.addEntries(new File("/tmp/demo.zip"), entries, out);
}
finally {
  IOUtils.closeQuietly(out);
}

Replace a ZIP archive entry from file

boolean replaced = ZipUtil.replaceEntry(new File("/tmp/demo.zip"), "doc/readme.txt", new File("/tmp/foo.txt"), new File("/tmp/new.zip"));

Replace a ZIP archive entry from byte array

boolean replaced = ZipUtil.replaceEntry(new File("/tmp/demo.zip"), "doc/readme.txt", "bar".getBytes(), new File("/tmp/new.zip"));

Replace a ZIP archive entry from file and byte array

ZipEntrySource[] entries = new ZipEntrySource[] {
    new FileSource("doc/readme.txt", new File("foo.txt")),
    new ByteSource("sample.txt", "bar".getBytes())
};
boolean replaced = ZipUtil.replaceEntries(new File("/tmp/demo.zip"), entries, new File("/tmp/new.zip"));

Add or replace entries in a ZIP archive

ZipEntrySource[] addedEntries = new ZipEntrySource[] {
        new FileSource("/path/in/zip/File1.txt", new File("/tmp/file1.txt")),
        new FileSource("/path/in/zip/File2.txt", new File("/tmp/file2.txt")),
        new FileSource("/path/in/zip/File3.txt", new File("/tmp/file2.txt")),
    };
ZipUtil.addOrReplaceEntries(new File("/tmp/demo.zip"), addedEntries);

Transforming

Transform a ZIP archive entry into uppercase

boolean transformed = ZipUtil.transformEntry(new File("/tmp/demo"), "sample.txt", new StringZipEntryTransformer() {
    protected String transform(ZipEntry zipEntry, String input) throws IOException {
        return input.toUpperCase();
    }
}, new File("/tmp/demo.zip"));

Comparison

Compare two ZIP archives (ignoring timestamps of the entries)

boolean equals = ZipUtil.archiveEquals(new File("/tmp/demo1.zip"), new File("/tmp/demo2.zip"));

Compare two ZIP archive entries with same name (ignoring timestamps of the entries)

boolean equals = ZipUtil.entryEquals(new File("/tmp/demo1.zip"), new File("/tmp/demo2.zip"), "foo.txt");

Compare two ZIP archive entries with different names (ignoring timestamps of the entries)

boolean equals = ZipUtil.entryEquals(new File("/tmp/demo1.zip"), new File("/tmp/demo2.zip"), "foo1.txt", "foo2.txt");

Progress bar

There have been multiple requests for a progress bar. See ZT Zip Progress Bar for a sample implementation.

Debugging

The library is using the slf4j-api logging framework. All the log statements are either DEBUG or TRACE level. Depending on the logging framework you are using a simple -Dorg.slf4j.simpleLogger.defaultLogLevel=debug or System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug"); will do the trick of showing log statements from the zt-zip library. You can further fine tune the levels and inclusion of log messages per package with your logging framework.

zt-zip's People

Contributors

andrus7k avatar antonarhipov avatar atsuiboupin avatar chenzhang22 avatar cilki avatar cordje avatar dependabot[bot] avatar domisum avatar flet avatar gbevin avatar jlleitschuh avatar madisp avatar mastap avatar mjomble avatar nowheresly avatar penn5 avatar shelajev avatar skeinaste avatar toomasr avatar vaults avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zt-zip's Issues

Make ZipUtil.pack more memory efficient for large directories

Consider calling dir.list() or using Files.walkFileTree (if you're fortunate enough to be able to use Java 1.7+) instead of File.listFiles() in ZipUtil.pack

This is something I just ran into recently with our own code to zip up directories so I started looking around for a fast/efficient library that would handle this for me.

In my case, I was zipping up a directory with 800,000 files in it (all at one level) and found that my program's memory was increasing by 500MB due to all of the File objects created by File.listFIles(). File.list() was about 50% less memory with just the string paths. You have to load each File individually but then you can allow it to be GC'ed. But the big savings came when using [Files.walkFileTree(Path,FileVisitor)](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree%28java.nio.file.Path, java.nio.file.FileVisitor%29). Both of these are probably a bit slower for smaller directories.

Add in-place methods

Add the following methods for in-place ZIP processing using a temporary file like (un)explode()

  • addEntry()
  • addEntries()
  • replaceEntry()
  • replaceEntries()
  • addOrReplaceEntries()
  • transformEntry()
  • transformEntries()

Add iterate methods for known entry names

  • void iterate(File zip, String[] names, ZipEntryCallback action) - you can make use of ZipFile.getEntry() in the implementation
  • void iterate(File zip, String[] names, ZipInfoCallback action)
  • void iterate(InputStream is, String[] names, ZipEntryCallback action) - (no performance benefit)

Can not unpack zip with original structure

Version 1.7
When I unpacking a zip file containing folders in Linux, all the entries in the zip are unpacked with name containing it's parent folders' names. Folders are omitted. But on windows everything is fine. Even on Linux some zip file can be unpacked correctly, while some can not.
Is anything wrong? Thanks for your help.

Structure of zip
image

Entries unpacked
image

Allow for extensibility of ZipUtil

I am considering zt-zip for some of my work but I need to extend ZipUtil. However, the class is marked as final and some of the interesting methods are marked as private. (Nevertheless - As my use-cases stabilize I would love to contribute back your project)

Existing non-compressed entries become compressed after adding new entry

I'm working with apk files and processing them programmatically using zt-zip. I discovered that after adding new entry into apk files some of them may stop working on a device. Logcat gave me a clue that this issue may be related to .ogg files. Then I noticed that in the original apk all *.ogg entries weren't compressed, which is not true for result archive. It really causes problems on Android devices. But, even if we try to abstract from Android system, library user expects to have entries unchanged. I think all entries should persist their compression state if a user isn't repacking whole archive.

Add artifacts to Maven Central

There are a lot of zeroturnaround artifacts in Maven Central, but unfortunately zt-zip isn't one of them. Could you publish your artifacts to Maven Central? As your project is release under the Apache V2 licence, I'd recommend using oss.sonatype.org to do this:

https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide

I appreciate your artifacts are currently published to repos.zeroturnaround.com, but for people external to your company it's preferable to rely upon only Maven Central if possible.

.jar file

Is it me or is there no output .jar for this project?

If so, how can people who do not use Maven use this library? :(

If I am mistaken, can you please point me to the .jar file?

method for zipping a single file or a list of files

I could not find a method in ZipUtil that takes as the argument just a single file, eg:

public static void packFile(File fileToZip, File zip);

As i see it this is not possible with zt-zip atm. I had to use the standard low-level java api.

packing a folder skips the folder

the method
public static void pack(File rootDir, File zip)
when called as
org.zeroturnaround.zip.ZipUtil.pack(sourceFolder, targetZipFile)
does not add the sourceFolder itself as the root folder to the zip file.
when extracting the archive, that folder is not there.

this is in contrast to for example winrar: right-click a folder, and zip it. the zip archive contains that folder as the single root.

i would have expected the winrar behavior, but i'm not an expert and maybe the current impl makes sense.

either way i believe it could be documented better, or a 2nd method with a different name could be added.

the solution isn't too hard thanks to the NameMapper:

    org.zeroturnaround.zip.ZipUtil.pack(sourceFolder, targetZipFile, new NameMapper() {
        public String map(String name) {
            return sourceFolder.getName() + "/" + name;
        }
    });

if nothing is changed in code then i would document this in javadoc, or else on the wiki.

Add charset support (java 7)

In Java 7 zip* constructors take charset as additional param. We should also support it by calling it via reflection and throw UnsupportedOperationException if it's older Java at runtime.

Push zt-zip releases to Bintray

Bintray offers developers the fastest way to publish and consume OSS software releases.

They promise easy integration with github projects, etc. Should be a nice way to promote zt-zip binaries.

java.lang.IllegalArgumentException: MALFORMED when using Zipfile containing umlauts

Hi guys, first off many thanks for the Lib: i have been using it quite well. This is untill I encountered some ZipEntries with german umlauts (ä,ö,ü and so on) in the Filename. My Program throws exceptions like this.

java.lang.IllegalArgumentException: MALFORMED
at java.util.zip.ZipCoder.toString(ZipCoder.java:58)
at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:297)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:121)
at org.zeroturnaround.zip.ZipUtil.iterate(ZipUtil.java:438)

this happend when using ZipUtil.iterate(Inputstream is, ZipEntryCallback zec).

Is there anything i can do to get this to work? Much appreciated, thanks for your time. Sebastian.

Exception handling: create subtype of RuntimeException

I personally would vote for throwing checked exceptions in a zip library. If any, then IO exceptions should be checked. But I understand the arguments against this, and don't want to argue ;-)

For runtime exceptions I would create a subclass such as ZipException extends RuntimeException. A RuntimeException can't be checked for in a single catch statement, this would be possible with ZipException. This can be helpful when passing the exception on to a higher layer that can finally deal with it.

Improve ZipUtil.unpack()

Investigate how to get rid of unnecessary IO operations made by FileUtils.forceMkdir() without causing OutOfMemoryError due to tracking all paths used.

Improve instructions

Help users how they can add zt-zip dependency to their project and how to configure/disable logging.

Keep modified and created dates when unziping

HI,
when un-zipping files the current date is set for file's creation and last modified date properties.
Would it be possible to preserve this dates by maybe change them after extracted?
Best regards
Bio

Packing EPUB3

I have an epub directory that must be zipped with following requirements;

Epub Directory

  • META-INF/
  • OEBPS/
  • mimetype

mimetype file must be first entry in zip file with no compression
OEBPS and META-INF directories and theirs subdirs and subfiles can be compressed in any level

When I use ZipUtil.pack method, everything is good but mimetype file does not first entry in zip file.

How can I do that with zt-zip ?

java.lang.NoSuchMethodError: org.zeroturnaround.zip.ZipUtil.addEntry(Ljava/io/File;Lorg/zeroturnaround/zip/ZipEntrySource;)V

Hello,

I have a strange problem :

  • when I run an application with jUnit or with a simple Main method, the class ZipUtil have 94 methods.
  • when I run in a web application (Spring, Tomcat) the class ZipUtils have 71 methods.

I have fully clean my project, my server, delete zt-zip from my Maven local repository but nothing works.

Methods that exist with junit does not exist in web app and vice versa.

It's a zt-zip bug or I missed something ?

See addEntry methods.

I run this code to analyze :

final Method[] methods = ZipUtil.class.getDeclaredMethods();
for (final Method method : methods) {
    System.out.println(method);
}

With web application :

static java.lang.Class org.zeroturnaround.zip.ZipUtil.class$(java.lang.String)
static com.zeroturnaround.bundled.org.slf4j.Logger org.zeroturnaround.zip.ZipUtil.access$100()
public static boolean org.zeroturnaround.zip.ZipUtil.handle(java.io.InputStream,java.lang.String,org.zeroturnaround.zip.ZipEntryCallback)
public static boolean org.zeroturnaround.zip.ZipUtil.handle(java.io.File,java.lang.String,org.zeroturnaround.zip.ZipEntryCallback)
static org.zeroturnaround.zip.ZipException org.zeroturnaround.zip.ZipUtil.access$400(java.io.IOException)
static void org.zeroturnaround.zip.ZipUtil.access$500(java.util.zip.ZipEntry,java.io.InputStream,java.util.zip.ZipOutputStream) throws java.io.IOException
static void org.zeroturnaround.zip.ZipUtil.access$600(org.zeroturnaround.zip.ZipEntrySource,java.util.zip.ZipOutputStream) throws java.io.IOException
private static void org.zeroturnaround.zip.ZipUtil.addEntry(org.zeroturnaround.zip.ZipEntrySource,java.util.zip.ZipOutputStream) throws java.io.IOException
private static void org.zeroturnaround.zip.ZipUtil.addEntry(java.util.zip.ZipEntry,java.io.InputStream,java.util.zip.ZipOutputStream) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,java.lang.String,byte[],java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,java.lang.String,java.io.File,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,org.zeroturnaround.zip.ZipEntrySource,java.io.File)
static java.util.Map org.zeroturnaround.zip.ZipUtil.access$700(org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[])
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.InputStream,org.zeroturnaround.zip.ZipEntryCallback)
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.File,org.zeroturnaround.zip.ZipEntryCallback)
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.File,org.zeroturnaround.zip.ZipInfoCallback)
private static org.zeroturnaround.zip.ZipException org.zeroturnaround.zip.ZipUtil.rethrow(java.io.IOException)
private static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.util.zip.ZipOutputStream,org.zeroturnaround.zip.NameMapper,java.lang.String) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,boolean)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,org.zeroturnaround.zip.NameMapper,int)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.pack(org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.File,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.File,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.InputStream,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.InputStream,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.addEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.addOrReplaceEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.archiveEquals(java.io.File,java.io.File)
private static boolean org.zeroturnaround.zip.ZipUtil.archiveEqualsInternal(java.io.File,java.io.File) throws java.io.IOException
private static java.util.Map org.zeroturnaround.zip.ZipUtil.byPath(org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[])
private static java.util.Map org.zeroturnaround.zip.ZipUtil.byPath(org.zeroturnaround.zip.ZipEntrySource[])
public static void org.zeroturnaround.zip.ZipUtil.closeQuietly(java.util.zip.ZipFile)
public static boolean org.zeroturnaround.zip.ZipUtil.containsAnyEntry(java.io.File,java.lang.String[])
public static boolean org.zeroturnaround.zip.ZipUtil.containsEntry(java.io.File,java.lang.String)
private static void org.zeroturnaround.zip.ZipUtil.copyEntries(java.io.File,java.util.zip.ZipOutputStream)
private static void org.zeroturnaround.zip.ZipUtil.copyEntry(java.util.zip.ZipEntry,java.io.InputStream,java.util.zip.ZipOutputStream) throws java.io.IOException
private static boolean org.zeroturnaround.zip.ZipUtil.doEntryEquals(java.util.zip.ZipFile,java.util.zip.ZipFile,java.lang.String,java.lang.String) throws java.io.IOException
private static byte[] org.zeroturnaround.zip.ZipUtil.doUnpackEntry(java.util.zip.ZipFile,java.lang.String) throws java.io.IOException
private static boolean org.zeroturnaround.zip.ZipUtil.doUnpackEntry(java.util.zip.ZipFile,java.lang.String,java.io.File) throws java.io.IOException
public static boolean org.zeroturnaround.zip.ZipUtil.entryEquals(java.util.zip.ZipFile,java.util.zip.ZipFile,java.lang.String,java.lang.String)
public static boolean org.zeroturnaround.zip.ZipUtil.entryEquals(java.io.File,java.io.File,java.lang.String)
public static boolean org.zeroturnaround.zip.ZipUtil.entryEquals(java.io.File,java.io.File,java.lang.String,java.lang.String)
public static void org.zeroturnaround.zip.ZipUtil.explode(java.io.File)
private static boolean org.zeroturnaround.zip.ZipUtil.metaDataEquals(java.lang.String,java.util.zip.ZipEntry,java.util.zip.ZipEntry) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.packEntries(java.io.File[],java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.packEntry(java.io.File,java.io.File)
public static byte[] org.zeroturnaround.zip.ZipUtil.packEntry(java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.repack(java.io.InputStream,java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.repack(java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.repack(java.io.File,java.io.File,int)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,java.lang.String,byte[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,java.lang.String,java.io.File,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,org.zeroturnaround.zip.ZipEntrySource,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntries(java.io.File,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntries(java.io.InputStream,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[],java.io.OutputStream)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.File,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.File,java.lang.String,org.zeroturnaround.zip.transform.ZipEntryTransformer,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.InputStream,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry,java.io.OutputStream)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.InputStream,java.lang.String,org.zeroturnaround.zip.transform.ZipEntryTransformer,java.io.OutputStream)
public static void org.zeroturnaround.zip.ZipUtil.unexplode(java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.unexplode(java.io.File)
public static byte[] org.zeroturnaround.zip.ZipUtil.unpackEntry(java.util.zip.ZipFile,java.lang.String)
public static byte[] org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.File,java.lang.String)
public static boolean org.zeroturnaround.zip.ZipUtil.unpackEntry(java.util.zip.ZipFile,java.lang.String,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.File,java.lang.String,java.io.File)
public static byte[] org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.InputStream,java.lang.String)
public static boolean org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.InputStream,java.lang.String,java.io.File) throws java.io.IOException

With jUnit :

static org.slf4j.Logger org.zeroturnaround.zip.ZipUtil.access$100()
public static boolean org.zeroturnaround.zip.ZipUtil.handle(java.io.InputStream,java.lang.String,org.zeroturnaround.zip.ZipEntryCallback)
public static boolean org.zeroturnaround.zip.ZipUtil.handle(java.io.File,java.lang.String,org.zeroturnaround.zip.ZipEntryCallback)
public static void org.zeroturnaround.zip.ZipUtil.unwrap(java.io.InputStream,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.unwrap(java.io.File,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.unwrap(java.io.File,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.unwrap(java.io.InputStream,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,java.lang.String,java.io.File,java.io.File)
static void org.zeroturnaround.zip.ZipUtil.addEntry(java.util.zip.ZipEntry,java.io.InputStream,java.util.zip.ZipOutputStream) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,java.lang.String,byte[])
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,java.lang.String,byte[],java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,java.lang.String,java.io.File)
static void org.zeroturnaround.zip.ZipUtil.addEntry(org.zeroturnaround.zip.ZipEntrySource,java.util.zip.ZipOutputStream) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,org.zeroturnaround.zip.ZipEntrySource,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.addEntry(java.io.File,org.zeroturnaround.zip.ZipEntrySource)
public static void org.zeroturnaround.zip.ZipUtil.packEntries(java.io.File[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.containsEntry(java.io.File,java.lang.String)
static org.zeroturnaround.zip.ZipException org.zeroturnaround.zip.ZipUtil.rethrow(java.io.IOException)
public static boolean org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.File,java.lang.String,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.unpackEntry(java.util.zip.ZipFile,java.lang.String,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.InputStream,java.lang.String,java.io.File) throws java.io.IOException
public static byte[] org.zeroturnaround.zip.ZipUtil.unpackEntry(java.util.zip.ZipFile,java.lang.String)
public static byte[] org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.File,java.lang.String)
public static byte[] org.zeroturnaround.zip.ZipUtil.unpackEntry(java.io.InputStream,java.lang.String)
private static byte[] org.zeroturnaround.zip.ZipUtil.doUnpackEntry(java.util.zip.ZipFile,java.lang.String) throws java.io.IOException
private static boolean org.zeroturnaround.zip.ZipUtil.doUnpackEntry(java.util.zip.ZipFile,java.lang.String,java.io.File) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.InputStream,java.lang.String[],org.zeroturnaround.zip.ZipEntryCallback)
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.File,java.lang.String[],org.zeroturnaround.zip.ZipEntryCallback)
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.File,org.zeroturnaround.zip.ZipEntryCallback)
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.File,java.lang.String[],org.zeroturnaround.zip.ZipInfoCallback)
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.File,org.zeroturnaround.zip.ZipInfoCallback)
public static void org.zeroturnaround.zip.ZipUtil.iterate(java.io.InputStream,org.zeroturnaround.zip.ZipEntryCallback)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.InputStream,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.InputStream,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.File,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.unpack(java.io.File,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.explode(java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.packEntry(java.io.File,java.io.File)
public static byte[] org.zeroturnaround.zip.ZipUtil.packEntry(java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.pack(org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,org.zeroturnaround.zip.NameMapper,int)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,boolean)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,org.zeroturnaround.zip.NameMapper)
public static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.io.File,int)
private static void org.zeroturnaround.zip.ZipUtil.pack(java.io.File,java.util.zip.ZipOutputStream,org.zeroturnaround.zip.NameMapper,java.lang.String) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.repack(java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.repack(java.io.InputStream,java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.repack(java.io.File,java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.unexplode(java.io.File,int)
public static void org.zeroturnaround.zip.ZipUtil.unexplode(java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.addEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.addEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[])
public static void org.zeroturnaround.zip.ZipUtil.removeEntry(java.io.File,java.lang.String,java.io.File)
public static void org.zeroturnaround.zip.ZipUtil.removeEntry(java.io.File,java.lang.String)
public static void org.zeroturnaround.zip.ZipUtil.removeEntries(java.io.File,java.lang.String[])
public static void org.zeroturnaround.zip.ZipUtil.removeEntries(java.io.File,java.lang.String[],java.io.File)
private static void org.zeroturnaround.zip.ZipUtil.copyEntries(java.io.File,java.util.zip.ZipOutputStream,java.util.Set)
private static void org.zeroturnaround.zip.ZipUtil.copyEntries(java.io.File,java.util.zip.ZipOutputStream)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,org.zeroturnaround.zip.ZipEntrySource)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,java.lang.String,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,java.lang.String,java.io.File,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,java.lang.String,byte[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,java.lang.String,byte[])
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntry(java.io.File,org.zeroturnaround.zip.ZipEntrySource,java.io.File)
static java.util.Map org.zeroturnaround.zip.ZipUtil.byPath(java.util.Collection)
static java.util.Map org.zeroturnaround.zip.ZipUtil.byPath(org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[])
static java.util.Map org.zeroturnaround.zip.ZipUtil.byPath(org.zeroturnaround.zip.ZipEntrySource[])
static void org.zeroturnaround.zip.ZipUtil.copyEntry(java.util.zip.ZipEntry,java.io.InputStream,java.util.zip.ZipOutputStream) throws java.io.IOException
public static boolean org.zeroturnaround.zip.ZipUtil.archiveEquals(java.io.File,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.entryEquals(java.util.zip.ZipFile,java.util.zip.ZipFile,java.lang.String,java.lang.String)
public static boolean org.zeroturnaround.zip.ZipUtil.entryEquals(java.io.File,java.io.File,java.lang.String,java.lang.String)
public static boolean org.zeroturnaround.zip.ZipUtil.entryEquals(java.io.File,java.io.File,java.lang.String)
private static boolean org.zeroturnaround.zip.ZipUtil.doEntryEquals(java.util.zip.ZipFile,java.util.zip.ZipFile,java.lang.String,java.lang.String) throws java.io.IOException
public static void org.zeroturnaround.zip.ZipUtil.closeQuietly(java.util.zip.ZipFile)
public static boolean org.zeroturnaround.zip.ZipUtil.containsAnyEntry(java.io.File,java.lang.String[])
static java.util.Set org.zeroturnaround.zip.ZipUtil.filterDirEntries(java.io.File,java.util.Collection)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.replaceEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[])
public static void org.zeroturnaround.zip.ZipUtil.addOrReplaceEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[])
public static void org.zeroturnaround.zip.ZipUtil.addOrReplaceEntries(java.io.File,org.zeroturnaround.zip.ZipEntrySource[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.InputStream,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry,java.io.OutputStream)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.File,java.lang.String,org.zeroturnaround.zip.transform.ZipEntryTransformer)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.File,java.lang.String,org.zeroturnaround.zip.transform.ZipEntryTransformer,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.File,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.InputStream,java.lang.String,org.zeroturnaround.zip.transform.ZipEntryTransformer,java.io.OutputStream)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntry(java.io.File,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry,java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntries(java.io.InputStream,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[],java.io.OutputStream)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntries(java.io.File,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[],java.io.File)
public static boolean org.zeroturnaround.zip.ZipUtil.transformEntries(java.io.File,org.zeroturnaround.zip.transform.ZipEntryTransformerEntry[])
private static boolean org.zeroturnaround.zip.ZipUtil.archiveEqualsInternal(java.io.File,java.io.File) throws java.io.IOException
private static boolean org.zeroturnaround.zip.ZipUtil.metaDataEquals(java.lang.String,java.util.zip.ZipEntry,java.util.zip.ZipEntry) throws java.io.IOException
private static boolean org.zeroturnaround.zip.ZipUtil.operateInPlace(java.io.File,org.zeroturnaround.zip.ZipUtil$InPlaceAction)

Aborting ZipUtil.iterate() only by exception

Problem: Aborting the iteration using ZipUtil.iterate() is only possible by throwing a (runtime) exception.

Use cases:

  • find out if a zip file contains a certain file
  • find out if a zip file contains more than x files

The best way, imo, would be to change the ZipInfoCallback.process method to return boolean. A bool false then means abort iteration.

At the moment there are 2 solutions:

  • let it iterate to the end even though the answer is known already
  • throw an exception, and then catch it, and check for the specific exception thrown and ignore it.
    this makes the code long and unreadable.

Make all the optional things available through a builder parameter.

We have a number of optional features that are wanted to include/exclude:

  • Preserving timestamps #19
  • Charset support #29, #30

I would even go further and implemented a destination archive (#17) through a parameters map.

Would be cool to simplify an api to somehting like:

ZipUtil.addEntry(File, ZipEntrySource, ZipUtilParams.preserveTimestamp().charset(charset).output(destFile)); 

Then by default all simple methods would be inplace and with no parametrization, however we won't need to pollute the API with all the variations of charsets, timestamps, existense/lack of destination). Methods would be simpler.

What do you think? Other features that we want to add later could be added there as well, so we won't need to change public api there.

unpackEntry a Directory Object fail.

I want to unpack a Directory ZipEntry,

I used this api ZipUtil.unpackEntry(new File("/tmp/demo.zip"), "dir", new File("/tmp"));,

but I get ZipException: java.io.FileNotFoundException: ...: open failed: EISDIR (Is a directory)

Is it mean I can't do this?

It does not support unicode character set

If the compressed file exists unicode character file name (such as Chinese, Japanese, etc.), will result in an exception.
Then I basically looked at the source code, this project is java.util.zip package. The default is to use hard-coded java.util.zip, thus resulting in a non-Western character does not work properly.

Unexpected default override behavior in pack()

The method

org.zeroturnaround.zip.ZipUtil.pack(sourceFolder, targetZipFile);

overwrites an existing zip. it is documented. i would have expected an exception instead.
it's probably too late to change that now. anyway, i wanted to leave my comment about it.

Add progress monitor support

Add a callback which gets events about the operation progress so users could update a progress bar e.g. Check other libraries for the same abstraction first.

How to create zip in memory?

I'm trying to get byte[] of the zip (i dont want to actualy do IO to file) from multiple ZipByteSource's but i cant find any suitable api for that. Is it possible with this library?

text relocations

when i use ZipUtil unpack a android apk file and repack it.
the new apk file is smaller than origin one
And i get some warning like
*.so has text relocations. This is wasting memory and is a security risk.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.