Package net.sf.basedb.util.zip
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 Summary
Fields Modifier and Type Field Description private ZipOutputStream
zip
-
Constructor Summary
Constructors Constructor Description ZipFilePacker()
Create a new packer that compresses files with the zip format. -
Method Summary
Modifier and Type Method Description void
close()
Finish the ZIP file.String
getDescription()
Get a short description of this file format that is suitable for display in selection list boxes.String
getFileExtension()
Gets the extension that files, packed with this tool, should have, for example,zip
ortar.gz
Don't include the first dot!String
getMimeType()
Gets the MIME type to give compressed files from this packervoid
pack(String entryName, InputStream in, long size, long lastModified)
Create a newZipEntry
and write the compressed data to it.void
setOutputStream(OutputStream out)
Wrap the output stream in aZipOutputStream
.
-
Field Details
-
zip
-
-
Constructor Details
-
ZipFilePacker
public ZipFilePacker()Create a new packer that compresses files with the zip format.
-
-
Method Details
-
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 interfaceFilePacker
- Returns:
- Always "Zip-archive (.zip)"
-
getFileExtension
Description copied from interface:FilePacker
Gets the extension that files, packed with this tool, should have, for example,zip
ortar.gz
Don't include the first dot!- Specified by:
getFileExtension
in interfaceFilePacker
- Returns:
- Always "zip"
-
getMimeType
Description copied from interface:FilePacker
Gets the MIME type to give compressed files from this packer- Specified by:
getMimeType
in interfaceFilePacker
- Returns:
- Always "application/zip"
-
setOutputStream
Wrap the output stream in aZipOutputStream
.- Specified by:
setOutputStream
in interfaceFilePacker
- Parameters:
out
- The output stream to write to
-
pack
public void pack(String entryName, InputStream in, long size, long lastModified) throws IOExceptionCreate a newZipEntry
and write the compressed data to it.- Specified by:
pack
in interfaceFilePacker
- Parameters:
entryName
- The name of the packed resource, including path informationin
- The input stream to read uncompressed data from, or null if the entry represents a directorysize
- The number of bytes of uncompressed datalastModified
- The time the contents was last modified, or 0 if not known- Throws:
IOException
- If there are any errors when reading or writing
-
close
Finish the ZIP file.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceFilePacker
- Throws:
IOException
- If there are any errors
-