Package com.mediaworx.ziputils
Class Zipper
java.lang.Object
com.mediaworx.ziputils.Zipper
Convenience class providing an easy way to create zip files and add files or folders to it. Uses Apache
commons-compress under the hood.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDirectory(String zipRelativePath) Adds a directory entry with the given relative path to the zip.voidAdds the given file to the zip archive using the given relative path.voidaddStringAsFile(String zipRelativePath, String plaintextContent) Adds the given plaintextContent as a file to the zip archive using the given relative path using the default encoding (UTF-8).voidaddStringAsFile(String zipRelativePath, String plaintextContent, String encoding) Adds the given plaintextContent as a file to the zip archive using the given relative path using the given encoding.voidfinish()Finalizes the zip file and writes it to the disk.
-
Constructor Details
-
Zipper
Creates a new zip file.- Parameters:
zipFilename- filename for the zipzipTargetFolderPath- path of the target folder where the zip should be stored (it will be created if it doesn't exist)- Throws:
IOException- Exceptions from the underlying package framework are bubbled up
-
-
Method Details
-
addFile
Adds the given file to the zip archive using the given relative path.- Parameters:
zipRelativePath- the path of the file relative to the zip rootfile- the file to be added- Throws:
IOException- Exceptions from the underlying package framework are bubbled up
-
addDirectory
Adds a directory entry with the given relative path to the zip.- Parameters:
zipRelativePath- the path of the directory relative to the zip root- Throws:
IOException- Exceptions from the underlying package framework are bubbled up
-
addStringAsFile
Adds the given plaintextContent as a file to the zip archive using the given relative path using the default encoding (UTF-8).- Parameters:
zipRelativePath- the path of the file relative to the zip rootplaintextContent- text content to be added as a file- Throws:
IOException- Exceptions from the underlying package framework are bubbled up
-
addStringAsFile
public void addStringAsFile(String zipRelativePath, String plaintextContent, String encoding) throws IOException Adds the given plaintextContent as a file to the zip archive using the given relative path using the given encoding.- Parameters:
zipRelativePath- the path of the file relative to the zip rootplaintextContent- text content to be added as a fileencoding- the encoding to be used- Throws:
IOException- Exceptions from the underlying package framework are bubbled up
-
finish
public void finish()Finalizes the zip file and writes it to the disk. It may be wise to call this method in afinallyblock to avoid dangling file streams.
-