Class ZipFilePacker

java.lang.Object
net.sf.basedb.util.zip.ZipFilePacker
All Implemented Interfaces:
AutoCloseable, FilePacker

public class ZipFilePacker extends Object implements FilePacker
This class packs files into a ZIP archive.
Version:
2.4
Author:
Martin, Nicklas
Last modified
$Date$
  • Field Details

    • zip

      private net.lingala.zip4j.io.outputstream.ZipOutputStream zip
    • password

      private String password
  • Constructor Details

    • ZipFilePacker

      public ZipFilePacker()
      Create a new packer that compresses files with the zip format.
  • Method Details

    • getDescription

      public String getDescription()
      Description copied from interface: FilePacker
      Get a short description of this file format that is suitable for display in selection list boxes.
      Specified by:
      getDescription in interface FilePacker
      Returns:
      Always "Zip-archive (.zip)"
    • getFileExtension

      public String getFileExtension()
      Description copied from interface: FilePacker
      Gets the extension that files, packed with this tool, should have, for example, zip or tar.gz Don't include the first dot!
      Specified by:
      getFileExtension in interface FilePacker
      Returns:
      Always "zip"
    • getMimeType

      public String getMimeType()
      Description copied from interface: FilePacker
      Gets the MIME type to give compressed files from this packer
      Specified by:
      getMimeType in interface FilePacker
      Returns:
      Always "application/zip"
    • setOutputStream

      public void setOutputStream(OutputStream out)
      Wrap the output stream in a ZipOutputStream.
      Specified by:
      setOutputStream in interface FilePacker
      Parameters:
      out - The output stream to write to
    • supportsEncryption

      public boolean supportsEncryption()
      Encryption is supported.
      Specified by:
      supportsEncryption in interface FilePacker
      Since:
      3.19.5
    • getPasswordParameter

      public PluginParameter<String> getPasswordParameter()
      Get the encyption password parameter.
      Specified by:
      getPasswordParameter in interface FilePacker
      Since:
      3.19.5
    • setPassword

      public void setPassword(String password)
      Description copied from interface: FilePacker
      Set the password to use for encrypting the archive. This method is only called if the implementation supports encryption and the user has entered a password.
      Specified by:
      setPassword in interface FilePacker
      Since:
      3.19.5
    • pack

      public void pack(String entryName, InputStream in, long size, long lastModified) throws IOException
      Create a new entry and write the compressed data to it.
      Specified by:
      pack in interface FilePacker
      Parameters:
      entryName - The name of the packed resource, including path information
      in - The input stream to read uncompressed data from, or null if the entry represents a directory
      size - The number of bytes of uncompressed data
      lastModified - The time the contents was last modified, or 0 if not known
      Throws:
      IOException - If there are any errors when reading or writing
    • close

      public void close() throws IOException
      Finish the ZIP file.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface FilePacker
      Throws:
      IOException - If there are any errors