Class ZipFileWriter

java.lang.Object
com.itextpdf.commons.utils.ZipFileWriter
All Implemented Interfaces:
Closeable, AutoCloseable

public class ZipFileWriter extends Object implements Closeable
Allows writing entries into a zip file.
  • Constructor Details

    • ZipFileWriter

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

    • addEntry

      public void addEntry (String fileName, File file) throws 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:
      IOException - if some I/O exception occurs
    • addEntry

      public void addEntry (String fileName, InputStream inputStream) throws 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:
      IOException - if some I/O exception occurs
    • addJsonEntry

      public void addJsonEntry (String fileName, Object objectToAdd) throws 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:
      IOException - if some I/O exception occurs
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException