Class ZipFileWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ZipFileWriter
    extends java.lang.Object
    implements java.io.Closeable
    Allows writing entries into a zip file.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static interface  ZipFileWriter.ZipWriter  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.zip.ZipOutputStream outputStream  
    • Constructor Summary

      Constructors 
      Constructor Description
      ZipFileWriter​(java.lang.String archivePath)
      Creates an instance for zip file writing.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEntry​(java.lang.String fileName, java.io.File file)
      Add file from disk into zip archive.
      void addEntry​(java.lang.String fileName, java.io.InputStream inputStream)
      Add file into zip archive with data from stream.
      private void addEntryToZip​(java.lang.String fileName, ZipFileWriter.ZipWriter writer)  
      void addJsonEntry​(java.lang.String fileName, java.lang.Object objectToAdd)
      Add file into zip archive with object serialized as JSON.
      void close()  
      • Methods inherited from class java.lang.Object

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

      • outputStream

        private final java.util.zip.ZipOutputStream outputStream
    • Constructor Detail

      • ZipFileWriter

        public ZipFileWriter​(java.lang.String archivePath)
                      throws java.io.IOException
        Creates an instance for zip file writing.
        Parameters:
        archivePath - the path to the zip file to write
        Throws:
        java.io.IOException - if some I/O exception occurs
    • Method Detail

      • addEntry

        public void addEntry​(java.lang.String fileName,
                             java.io.File file)
                      throws java.io.IOException
        Add file from disk into zip archive.
        Parameters:
        fileName - the target name of the file inside zip after writing
        file - the path to the file on disk to archive
        Throws:
        java.io.IOException - if some I/O exception occurs
      • addEntry

        public void addEntry​(java.lang.String fileName,
                             java.io.InputStream inputStream)
                      throws java.io.IOException
        Add file into zip archive with data from stream.
        Parameters:
        fileName - the target name of the file inside zip after writing
        inputStream - the input stream to archive
        Throws:
        java.io.IOException - if some I/O exception occurs
      • addJsonEntry

        public void addJsonEntry​(java.lang.String fileName,
                                 java.lang.Object objectToAdd)
                          throws java.io.IOException
        Add file into zip archive with object serialized as JSON.
        Parameters:
        fileName - the target name of the file inside zip after writing
        objectToAdd - the object to serialize as JSON
        Throws:
        java.io.IOException - if some I/O exception occurs
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • addEntryToZip

        private void addEntryToZip​(java.lang.String fileName,
                                   ZipFileWriter.ZipWriter writer)
                            throws java.io.IOException
        Throws:
        java.io.IOException