Class ZipCreator

java.lang.Object
org.projecthusky.common.utils.ZipCreator

public class ZipCreator extends Object
This class provides the functions to create zip files
  • Constructor Details

    • ZipCreator

      public ZipCreator(OutputStream outputStream)
      Creates a new Object which provides the needed methods
      Parameters:
      outputStream - the outputStream, which is used to write the contents to
    • ZipCreator

      public ZipCreator(String filePath)
      Creates a new Object which provides the needed methods
      Parameters:
      filePath - the path to the file, which is used to write the contents to
  • Method Details

    • addZipItem

      public void addZipItem(InputStream data, String pathInZipFile) throws IOException
      Adds an InputStream as ZipEntry to the ZipFile
      Parameters:
      data - Contains the file to compress as InputStream
      pathInZipFile - Contains the relative path only in that zip file
      Throws:
      IOException - if the file could not be read
    • addZipItem

      public void addZipItem(String pathInZipFile) throws IOException
      Adds a directory as ZipEntry to the ZipFile
      Parameters:
      pathInZipFile - Contains the relative path only in that zip file
      Throws:
      IOException - if the file could not be read
    • addZipItem

      public void addZipItem(String filePath, String pathInZipFile) throws IOException
      Adds an InputStream as ZipEntry to the ZipFile
      Parameters:
      filePath - Contains the path to the file to add as zip item
      pathInZipFile - Contains the relative path only in that zip file
      Throws:
      IOException - if the file could not be read
    • closeZip

      public void closeZip() throws IOException
      Closes the stream. It only has to be called when no more entries will be added.
      Throws:
      IOException - if the file could not be read