java.lang.Object
io.github.astrapi69.zip.Zipper
All Implemented Interfaces:
ZipModel

public class Zipper extends Object implements ZipModel
The Zipper class provides functionality to create ZIP archives from directories or files. It supports various compression methods and allows customization through builder pattern.
  • Constructor Details

    • Zipper

      public Zipper()
      Instantiates a new Zipper object
    • Zipper

      public Zipper(File dirToZip, File zipFile)
      Instantiates a new Zipper object
      Parameters:
      dirToZip - the directory to zip
      zipFile - the zip file
    • Zipper

      public Zipper(File dirToZip, File zipFile, FilenameFilter filter)
      Instantiates a new Zipper object
      Parameters:
      dirToZip - the directory to zip
      zipFile - the zip file
      filter - the file name filter
    • Zipper

      public Zipper(int compressionMethod, File directoryToZip, String dirToStart, int fileCounter, FilenameFilter fileFilter, long fileLength, File zipFile, String zipFileComment, String zipFileName, ZipFile zipFileObj, int zipLevel)
      Instantiates a new Zipper object with detailed parameters.
      Parameters:
      compressionMethod - the compression method
      directoryToZip - the directory to zip
      dirToStart - the directory to start
      fileCounter - the file counter
      fileFilter - the file name filter
      fileLength - the total length of files being zipped
      zipFile - the zip file
      zipFileComment - the zip file comment
      zipFileName - the zip file name
      zipFileObj - the zip file object
      zipLevel - the compression level
  • Method Details

    • builder

      public static Zipper.ZipperBuilder builder()
      Provides a builder to construct a Zipper object with desired parameters.
      Returns:
      a new ZipperBuilder instance
    • getCompressionMethod

      public int getCompressionMethod()
      Gets the compression method used for zipping.
      Specified by:
      getCompressionMethod in interface ZipModel
      Returns:
      the compression method
    • setCompressionMethod

      public void setCompressionMethod(int compressionMethod)
      Sets the compression method for zipping.
      Specified by:
      setCompressionMethod in interface ZipModel
      Parameters:
      compressionMethod - the new compression method
    • getDirectoryToZip

      public File getDirectoryToZip()
      Gets the directory to be zipped.
      Specified by:
      getDirectoryToZip in interface ZipModel
      Returns:
      the directory to zip
    • setDirectoryToZip

      public void setDirectoryToZip(File directoryToZip)
      Sets the directory to be zipped.
      Specified by:
      setDirectoryToZip in interface ZipModel
      Parameters:
      directoryToZip - the new directory to zip
    • getDirToStart

      public String getDirToStart()
      Gets the starting directory within the ZIP archive.
      Specified by:
      getDirToStart in interface ZipModel
      Returns:
      the directory to start zipping
    • setDirToStart

      public void setDirToStart(String dirToStart)
      Sets the starting directory within the ZIP archive.
      Specified by:
      setDirToStart in interface ZipModel
      Parameters:
      dirToStart - the new directory to start zipping
    • getFileCounter

      public int getFileCounter()
      Gets the total number of files zipped.
      Specified by:
      getFileCounter in interface ZipModel
      Returns:
      the file counter
    • setFileCounter

      public void setFileCounter(int fileCounter)
      Sets the total number of files zipped.
      Specified by:
      setFileCounter in interface ZipModel
      Parameters:
      fileCounter - the new file counter
    • getFileFilter

      public FilenameFilter getFileFilter()
      Gets the file name filter used during zipping.
      Specified by:
      getFileFilter in interface ZipModel
      Returns:
      the file name filter
    • setFileFilter

      public void setFileFilter(FilenameFilter fileFilter)
      Sets the file name filter used during zipping.
      Specified by:
      setFileFilter in interface ZipModel
      Parameters:
      fileFilter - the new file name filter
    • getFileLength

      public long getFileLength()
      Gets the total length of files being zipped.
      Specified by:
      getFileLength in interface ZipModel
      Returns:
      the total file length
    • setFileLength

      public void setFileLength(long fileLength)
      Sets the total length of files being zipped.
      Specified by:
      setFileLength in interface ZipModel
      Parameters:
      fileLength - the new total file length
    • getZipFile

      public File getZipFile()
      Gets the target ZIP file object.
      Specified by:
      getZipFile in interface ZipModel
      Returns:
      the zip file
    • setZipFile

      public void setZipFile(File zipFile)
      Sets the target ZIP file object.
      Specified by:
      setZipFile in interface ZipModel
      Parameters:
      zipFile - the new zip file
    • getZipFileComment

      public String getZipFileComment()
      Gets the comment associated with the ZIP file.
      Specified by:
      getZipFileComment in interface ZipModel
      Returns:
      the zip file comment
    • setZipFileComment

      public void setZipFileComment(String zipFileComment)
      Sets the comment associated with the ZIP file.
      Specified by:
      setZipFileComment in interface ZipModel
      Parameters:
      zipFileComment - the new zip file comment
    • getZipFileName

      public String getZipFileName()
      Gets the name of the ZIP file.
      Specified by:
      getZipFileName in interface ZipModel
      Returns:
      the zip file name
    • setZipFileName

      public void setZipFileName(String zipFileName)
      Sets the name of the ZIP file.
      Specified by:
      setZipFileName in interface ZipModel
      Parameters:
      zipFileName - the new zip file name
    • getZipFileObj

      public ZipFile getZipFileObj()
      Gets the ZIP file object.
      Specified by:
      getZipFileObj in interface ZipModel
      Returns:
      the zip file object
    • setZipFileObj

      public void setZipFileObj(ZipFile zipFileObj)
      Sets the ZIP file object.
      Specified by:
      setZipFileObj in interface ZipModel
      Parameters:
      zipFileObj - the new zip file object
    • getZipLevel

      public int getZipLevel()
      Gets the compression level used during zipping.
      Specified by:
      getZipLevel in interface ZipModel
      Returns:
      the compression level
    • setZipLevel

      public void setZipLevel(int zipLevel)
      Sets the compression level used during zipping.
      Specified by:
      setZipLevel in interface ZipModel
      Parameters:
      zipLevel - the new compression level
    • toBuilder

      public Zipper.ZipperBuilder toBuilder()
      Creates a new ZipperBuilder initialized with current object's properties.
      Returns:
      a builder instance with current configuration
    • zip

      public Optional<ZipErrorCodes> zip()
      Creates a ZIP archive of the specified directory and its contents.
      Returns:
      an optional error code if any issue occurs during the operation