java.lang.Object
io.github.astrapi69.zip.Zipper
- All Implemented Interfaces:
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder class for constructingZipper
objects with desired parameters. -
Constructor Summary
ConstructorsConstructorDescriptionZipper()
Instantiates a newZipper
objectZipper
(int compressionMethod, File directoryToZip, String dirToStart, int fileCounter, FilenameFilter fileFilter, long fileLength, File zipFile, String zipFileComment, String zipFileName, ZipFile zipFileObj, int zipLevel) Instantiates a newZipper
object with detailed parameters.Instantiates a newZipper
objectZipper
(File dirToZip, File zipFile, FilenameFilter filter) Instantiates a newZipper
object -
Method Summary
Modifier and TypeMethodDescriptionstatic Zipper.ZipperBuilder
builder()
Provides a builder to construct aZipper
object with desired parameters.int
Gets the compression method used for zipping.Gets the directory to be zipped.Gets the starting directory within the ZIP archive.int
Gets the total number of files zipped.Gets the file name filter used during zipping.long
Gets the total length of files being zipped.Gets the target ZIP file object.Gets the comment associated with the ZIP file.Gets the name of the ZIP file.Gets the ZIP file object.int
Gets the compression level used during zipping.void
setCompressionMethod
(int compressionMethod) Sets the compression method for zipping.void
setDirectoryToZip
(File directoryToZip) Sets the directory to be zipped.void
setDirToStart
(String dirToStart) Sets the starting directory within the ZIP archive.void
setFileCounter
(int fileCounter) Sets the total number of files zipped.void
setFileFilter
(FilenameFilter fileFilter) Sets the file name filter used during zipping.void
setFileLength
(long fileLength) Sets the total length of files being zipped.void
setZipFile
(File zipFile) Sets the target ZIP file object.void
setZipFileComment
(String zipFileComment) Sets the comment associated with the ZIP file.void
setZipFileName
(String zipFileName) Sets the name of the ZIP file.void
setZipFileObj
(ZipFile zipFileObj) Sets the ZIP file object.void
setZipLevel
(int zipLevel) Sets the compression level used during zipping.Creates a newZipperBuilder
initialized with current object's properties.zip()
Creates a ZIP archive of the specified directory and its contents.
-
Constructor Details
-
Zipper
public Zipper()Instantiates a newZipper
object -
Zipper
Instantiates a newZipper
object- Parameters:
dirToZip
- the directory to zipzipFile
- the zip file
-
Zipper
Instantiates a newZipper
object- Parameters:
dirToZip
- the directory to zipzipFile
- the zip filefilter
- 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 newZipper
object with detailed parameters.- Parameters:
compressionMethod
- the compression methoddirectoryToZip
- the directory to zipdirToStart
- the directory to startfileCounter
- the file counterfileFilter
- the file name filterfileLength
- the total length of files being zippedzipFile
- the zip filezipFileComment
- the zip file commentzipFileName
- the zip file namezipFileObj
- the zip file objectzipLevel
- the compression level
-
-
Method Details
-
builder
Provides a builder to construct aZipper
object with desired parameters.- Returns:
- a new
ZipperBuilder
instance
-
getCompressionMethod
public int getCompressionMethod()Gets the compression method used for zipping.- Specified by:
getCompressionMethod
in interfaceZipModel
- Returns:
- the compression method
-
setCompressionMethod
public void setCompressionMethod(int compressionMethod) Sets the compression method for zipping.- Specified by:
setCompressionMethod
in interfaceZipModel
- Parameters:
compressionMethod
- the new compression method
-
getDirectoryToZip
Gets the directory to be zipped.- Specified by:
getDirectoryToZip
in interfaceZipModel
- Returns:
- the directory to zip
-
setDirectoryToZip
Sets the directory to be zipped.- Specified by:
setDirectoryToZip
in interfaceZipModel
- Parameters:
directoryToZip
- the new directory to zip
-
getDirToStart
Gets the starting directory within the ZIP archive.- Specified by:
getDirToStart
in interfaceZipModel
- Returns:
- the directory to start zipping
-
setDirToStart
Sets the starting directory within the ZIP archive.- Specified by:
setDirToStart
in interfaceZipModel
- Parameters:
dirToStart
- the new directory to start zipping
-
getFileCounter
public int getFileCounter()Gets the total number of files zipped.- Specified by:
getFileCounter
in interfaceZipModel
- Returns:
- the file counter
-
setFileCounter
public void setFileCounter(int fileCounter) Sets the total number of files zipped.- Specified by:
setFileCounter
in interfaceZipModel
- Parameters:
fileCounter
- the new file counter
-
getFileFilter
Gets the file name filter used during zipping.- Specified by:
getFileFilter
in interfaceZipModel
- Returns:
- the file name filter
-
setFileFilter
Sets the file name filter used during zipping.- Specified by:
setFileFilter
in interfaceZipModel
- Parameters:
fileFilter
- the new file name filter
-
getFileLength
public long getFileLength()Gets the total length of files being zipped.- Specified by:
getFileLength
in interfaceZipModel
- Returns:
- the total file length
-
setFileLength
public void setFileLength(long fileLength) Sets the total length of files being zipped.- Specified by:
setFileLength
in interfaceZipModel
- Parameters:
fileLength
- the new total file length
-
getZipFile
Gets the target ZIP file object.- Specified by:
getZipFile
in interfaceZipModel
- Returns:
- the zip file
-
setZipFile
Sets the target ZIP file object.- Specified by:
setZipFile
in interfaceZipModel
- Parameters:
zipFile
- the new zip file
-
getZipFileComment
Gets the comment associated with the ZIP file.- Specified by:
getZipFileComment
in interfaceZipModel
- Returns:
- the zip file comment
-
setZipFileComment
Sets the comment associated with the ZIP file.- Specified by:
setZipFileComment
in interfaceZipModel
- Parameters:
zipFileComment
- the new zip file comment
-
getZipFileName
Gets the name of the ZIP file.- Specified by:
getZipFileName
in interfaceZipModel
- Returns:
- the zip file name
-
setZipFileName
Sets the name of the ZIP file.- Specified by:
setZipFileName
in interfaceZipModel
- Parameters:
zipFileName
- the new zip file name
-
getZipFileObj
Gets the ZIP file object.- Specified by:
getZipFileObj
in interfaceZipModel
- Returns:
- the zip file object
-
setZipFileObj
Sets the ZIP file object.- Specified by:
setZipFileObj
in interfaceZipModel
- Parameters:
zipFileObj
- the new zip file object
-
getZipLevel
public int getZipLevel()Gets the compression level used during zipping.- Specified by:
getZipLevel
in interfaceZipModel
- Returns:
- the compression level
-
setZipLevel
public void setZipLevel(int zipLevel) Sets the compression level used during zipping.- Specified by:
setZipLevel
in interfaceZipModel
- Parameters:
zipLevel
- the new compression level
-
toBuilder
Creates a newZipperBuilder
initialized with current object's properties.- Returns:
- a builder instance with current configuration
-
zip
Creates a ZIP archive of the specified directory and its contents.- Returns:
- an optional error code if any issue occurs during the operation
-