Class ZipUtils


  • public class ZipUtils
    extends Object
    Utilities for accessing content in zip files
    Author:
    markr
    • Constructor Detail

      • ZipUtils

        public ZipUtils()
    • Method Detail

      • createZipEntryInputStream

        public static PlanitZipInputStream createZipEntryInputStream​(URL zipFileLocation,
                                                                     String zipEntryFileName,
                                                                     boolean logInfo)
                                                              throws URISyntaxException,
                                                                     IOException
        Collect the input stream for a given zip file entry. The returned wrapper stream should be positioned at the beginning of the internal file Note that invoked needs to close the input stream when done! This approach uses a ZipInputStream rather than a ZipFile for performance reasons as it appears to be around 5 times faster for a regular sized zip file
        Parameters:
        zipFileLocation - of the zip file
        zipEntryFileName - of the file within the zip
        logInfo - when true log extensive information on entries in zip file, file size and whether the file exists for debugging purposes
        Returns:
        input stream created, if file not found by iterating over entries null is returned
        Throws:
        URISyntaxException - thrown if error
        IOException - thrown if input stream cannot be closed when necessary
      • createZipEntryInputStream

        public static PlanitZipFileInputStream createZipEntryInputStream​(ZipFile zipFile,
                                                                         String zipEntryFileName)
                                                                  throws URISyntaxException,
                                                                         IOException
        Collect the input stream for a given zip file entry. The returned wrapper stream is positioned at the beginning of the internal file
        Parameters:
        zipFile - to use
        zipEntryFileName - of the file within the zip
        Returns:
        input stream created, if file not found by iterating over entries null is returned
        Throws:
        URISyntaxException - thrown if error
        IOException - thrown if input stream cannot be closed when necessary
      • positionZipEntryInputStream

        public static boolean positionZipEntryInputStream​(ZipInputStream zipInputStream,
                                                          String zipEntryFileName)
        Move the passed in zip input stream to the starting point of the given zip file entry.
        Parameters:
        zipInputStream - to use
        zipEntryFileName - of the file within the zip
        Returns:
        true when successfully positioned the input stream, false otherwise