Class ZipMisc


  • public class ZipMisc
    extends Object
    Utilities for mucking with zip files.
    • Constructor Detail

      • ZipMisc

        public ZipMisc()
    • Method Detail

      • read

        public static void read​(File input,
                                String toRead,
                                com.diffplug.common.base.Throwing.Specific.Consumer<InputStream,​IOException> reader)
                         throws IOException
        Reads the given entry from the zip.
        Parameters:
        input - a zip file
        toRead - a path within that zip file
        reader - will be called with an InputStream containing the contents of that entry in the zip file
        Throws:
        IOException
      • read

        public static String read​(File input,
                                  String toRead)
                           throws IOException
        Reads the given entry from the zip.
        Parameters:
        input - a zip file
        toRead - a path within that zip file
        Returns:
        the given path within the zip file decoded as a UTF8 string, with only unix newlines.
        Throws:
        IOException
      • modify

        public static void modify​(com.diffplug.common.io.ByteSource input,
                                  com.diffplug.common.io.ByteSink output,
                                  Map<String,​Function<byte[],​byte[]>> toModify,
                                  Predicate<String> toOmit)
                           throws IOException
        Modifies only the specified entries in a zip file.
        Parameters:
        input - a source from a zip file
        output - an output to a zip file
        toModify - a map from path to an input stream for the entries you'd like to change
        toOmit - a set of entries you'd like to leave out of the zip
        Throws:
        IOException
      • zip

        public static void zip​(File input,
                               String pathWithinArchive,
                               File output)
                        throws IOException
        Creates a single-entry zip file.
        Parameters:
        input - an uncompressed file
        pathWithinArchive - the path within the archive
        output - the new zip file it will be compressed into
        Throws:
        IOException
      • unzip

        public static void unzip​(File input,
                                 File destinationDir)
                          throws IOException
        Unzips a directory to a folder.
        Parameters:
        input - a zip file
        destinationDir - where the zip will be extracted to
        Throws:
        IOException