Package utils.common

Class ZipUtil


  • @Singleton
    public class ZipUtil
    extends java.lang.Object
    Utility class that does zipping and unzipping.
    • Constructor Summary

      Constructors 
      Constructor Description
      ZipUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addDataToZip​(java.util.zip.ZipOutputStream zipOut, java.lang.String data, java.lang.String pathInZip)
      Writes the given data as a file to the zip stream using pathInZip as the path in the zip package
      static void addDirToZip​(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file)
      Writes a directory to the ZipOutputStream walking recursively through the file system.
      static void addFileToZip​(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file)
      Writes the file using its filename into the ZipOutputStream under path zipRoot in the zip package
      static void addFileToZip​(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path zipFilename, java.nio.file.Path file)
      Writes the file into the ZipOutputStream under the path '/zipRoot/zipFilename'
      static void addToZip​(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file)
      Add a path (can be a file or a directory) to a ZipOutputStream under path zipRoot in the zip
      static java.nio.file.Path unzip​(java.nio.file.Path fileToUnzip, java.nio.file.Path destDir)
      Unzips the given file.
      static void zipFiles​(java.util.List<java.nio.file.Path> filesToZip, java.nio.file.Path zipFile)
      Generates a zip archive file and writes a list of files into it
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ZipUtil

        public ZipUtil()
    • Method Detail

      • unzip

        public static java.nio.file.Path unzip​(java.nio.file.Path fileToUnzip,
                                               java.nio.file.Path destDir)
                                        throws java.io.IOException
        Unzips the given file. Creates a new directory in the system's temp directory and writes the zip's content in there. The method can handle recursive unzipping of subdirectories.
        Throws:
        java.io.IOException
      • zipFiles

        public static void zipFiles​(java.util.List<java.nio.file.Path> filesToZip,
                                    java.nio.file.Path zipFile)
                             throws java.io.IOException
        Generates a zip archive file and writes a list of files into it
        Throws:
        java.io.IOException
      • addToZip

        public static void addToZip​(java.util.zip.ZipOutputStream out,
                                    java.nio.file.Path zipRoot,
                                    java.nio.file.Path file)
                             throws java.io.IOException
        Add a path (can be a file or a directory) to a ZipOutputStream under path zipRoot in the zip
        Throws:
        java.io.IOException
      • addDirToZip

        public static void addDirToZip​(java.util.zip.ZipOutputStream out,
                                       java.nio.file.Path zipRoot,
                                       java.nio.file.Path file)
                                throws java.io.IOException
        Writes a directory to the ZipOutputStream walking recursively through the file system.
        Throws:
        java.io.IOException
      • addFileToZip

        public static void addFileToZip​(java.util.zip.ZipOutputStream out,
                                        java.nio.file.Path zipRoot,
                                        java.nio.file.Path file)
                                 throws java.io.IOException
        Writes the file using its filename into the ZipOutputStream under path zipRoot in the zip package
        Throws:
        java.io.IOException
      • addFileToZip

        public static void addFileToZip​(java.util.zip.ZipOutputStream out,
                                        java.nio.file.Path zipRoot,
                                        java.nio.file.Path zipFilename,
                                        java.nio.file.Path file)
                                 throws java.io.IOException
        Writes the file into the ZipOutputStream under the path '/zipRoot/zipFilename'
        Throws:
        java.io.IOException
      • addDataToZip

        public static void addDataToZip​(java.util.zip.ZipOutputStream zipOut,
                                        java.lang.String data,
                                        java.lang.String pathInZip)
                                 throws java.io.IOException
        Writes the given data as a file to the zip stream using pathInZip as the path in the zip package
        Throws:
        java.io.IOException