Class Zip


  • public final class Zip
    extends java.lang.Object
    A fast, minimal, and somewhat garbage zip implementation. This exists because graal doesn't yet support ZipFile, and ZipInputStream doesn't have the performance we'd like (*). If you're reading this, you almost certainly want ZipFile instead.

    If you're reading this because you're fixing a bug, sorry.

    (*) A benchmark that iterates over all of the entries in rt.jar takes 6.97ms to run with this implementation and 202.99ms with ZipInputStream. (Those are averages across 100 reps, and I verified they're doing the same work.) This is likely largely due to ZipInputStream reading the entire file from the beginning to scan the local headers, whereas this implementation (and ZipFile) only read the central directory. Iterating over the entries (but not reading the data) is an interesting benchmark because we typically only read ~10% of the compile-time classpath, so most time is spent just scanning entry names. And rt.jar is an interesting test case because every compilation has to read it, and it dominates the size of the classpath for small compilations.

    Implementation notes:

    • Leading garbage may be supported, since the archive is read backwards using the central directory. Archives modified with zip -A may not be supported. Trailing garbage is not supported.
    • UTF-8 is the only supported encoding.
    • STORED and DEFLATE are the only supported compression methods.
    • Zip files larger than Integer.MAX_VALUE bytes are not supported.
    • The only supported ZIP64 field is ENDTOT. This implementation assumes that the ZIP64 end header is present only if ENDTOT in EOCD header is 0xFFFF.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Zip.Entry
      An entry in a zip archive.
      static class  Zip.ZipIterable
      Provides an Iterable of Zip.Entry over a zip archive.
    • Method Summary

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait