@Immutable @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public class ZipDriver extends FsCharsetArchiveDriver<ZipArchiveEntry> implements ZipOutputStreamParameters, ZipFileParameters<ZipArchiveEntry>
JarDriver instead.
This driver does not check the CRC value of any entries in existing
archives - use CheckedZipDriver or CheckedJarDriver instead.
CheckedZipDriver| Modifier and Type | Field and Description |
|---|---|
private IOPool<?> |
ioPool |
private static Logger |
logger |
private static Charset |
ZIP_CHARSET
The character set for entry names and comments in "traditional"
ZIP files, which is
"IBM437". |
| Modifier | Constructor and Description |
|---|---|
|
ZipDriver(IOPoolProvider ioPoolProvider)
Constructs a new ZIP file driver.
|
protected |
ZipDriver(IOPoolProvider ioPoolProvider,
Charset charset)
Constructs a new ZIP file driver.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
check(ZipInputShop input,
ZipArchiveEntry entry)
Whether or not the content of the given entry shall get
checked/authenticated when reading it.
|
protected KeyManagerProvider |
getKeyManagerProvider()
Returns the provider for key managers for accessing protected resources
(encryption).
|
protected KeyProviderSyncStrategy |
getKeyProviderSyncStrategy()
Returns the key provider sync strategy.
|
int |
getLevel()
Returns the compression level for entries.
|
int |
getMethod()
Returns the default compression method for entries.
|
OptionOutputSocket |
getOutputSocket(FsController<?> controller,
FsEntryName name,
BitField<FsOutputOption> options,
Entry template)
This implementation modifies
options in the following way before
it forwards the call to controller:
FsOutputOption.STORE is set. |
protected IOPool<?> |
getPool() |
boolean |
getPostambled()
Returns the flag for allowing a postamble of arbitrary length.
|
boolean |
getPreambled()
Returns the flag for allowing a preamble.
|
boolean |
getRedundantContentSupport() |
boolean |
getRedundantMetaDataSupport() |
URI |
mountPointUri(FsModel model)
A template method which derives the URI which represents the mount point
of the given file system model as the base resource URI for looking up
KeyProviders. |
FsController<?> |
newController(FsModel model,
FsController<?> parent)
The implementation in the class
ZipDriver returns the expression
new ZipController(superNewController(model, parent), this). |
ZipArchiveEntry |
newEntry(String name)
Returns a new ZIP entry with the given
name. |
ZipArchiveEntry |
newEntry(String name,
Entry.Type type,
Entry template,
BitField<FsOutputOption> mknod) |
ZipArchiveEntry |
newEntry(String name,
ZipEntry template) |
InputShop<ZipArchiveEntry> |
newInputShop(FsModel model,
InputSocket<?> input)
The implementation in the class
ZipDriver acquires a read only
file from the given socket and forwards the call to
newInputShop(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.socket.InputSocket<?>). |
protected InputShop<ZipArchiveEntry> |
newInputShop(FsModel model,
ReadOnlyFile rof) |
protected OutputShop<ZipArchiveEntry> |
newOutputShop(FsModel model,
OptionOutputSocket output,
ZipInputShop source) |
OutputShop<ZipArchiveEntry> |
newOutputShop(FsModel model,
OutputSocket<?> output,
InputShop<ZipArchiveEntry> source)
This implementation first checks if
FsOutputOption.GROW is set
for the given output socket. |
protected OutputShop<ZipArchiveEntry> |
newOutputShop(FsModel model,
OutputStream out,
ZipInputShop source) |
private OutputShop<ZipArchiveEntry> |
newOutputShop0(FsModel model,
OptionOutputSocket output,
ZipInputShop source) |
protected boolean |
process(ZipArchiveEntry input,
ZipArchiveEntry output)
Returns
true if and only if the content of the given input
target entry needs processing when it gets copied to the given output
target entry. |
(package private) boolean |
process(ZipInputShop input,
ZipArchiveEntry local,
ZipArchiveEntry peer) |
(package private) boolean |
process(ZipOutputShop output,
ZipArchiveEntry local,
ZipArchiveEntry peer) |
URI |
resourceUri(FsModel model,
String name)
A template method which derives the resource URI for looking up a
KeyProvider from the given file system model and entry name. |
protected FsController<?> |
superNewController(FsModel model,
FsController<?> parent)
Equivalent to calling
FsArchiveDriver.newController(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.fs.FsController<?>) on the FsArchiveDriver
class. |
protected ZipCryptoParameters |
zipCryptoParameters(FsModel model,
Charset charset)
Returns the ZIP crypto parameters for the given file system model
and character set or
null if not available. |
(package private) ZipCryptoParameters |
zipCryptoParameters(ZipInputShop input) |
(package private) ZipCryptoParameters |
zipCryptoParameters(ZipOutputShop output) |
assertEncodable, getCharset, toString, toZipOrTarEntryNamegetClosedIcon, getInputSocket, getOpenIcon, isFederated, newEntry, newInputStream, newOutputStream, newReadOnlyFilegetPriorityclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetOverheadSizegetCharsetprivate final IOPool<?> ioPool
private static final Logger logger
private static final Charset ZIP_CHARSET
"IBM437".public ZipDriver(IOPoolProvider ioPoolProvider)
ZIP_CHARSET for encoding entry names
and comments.ioPoolProvider - the provider for I/O entry pools for allocating
temporary I/O entries (buffers).protected ZipDriver(IOPoolProvider ioPoolProvider, Charset charset)
ioPoolProvider - the provider for I/O entry pools for allocating
temporary I/O entries (buffers).charset - the character set for encoding entry names and comments.protected boolean check(ZipInputShop input, ZipArchiveEntry entry)
true and the check fails,
then an IOException gets thrown.entry.isEncrypted().protected KeyManagerProvider getKeyManagerProvider()
The implementation in ZipDriver always returns
KeyManagerLocator.SINGLETON.
When overriding this method, subsequent calls must return the same
object.
protected KeyProviderSyncStrategy getKeyProviderSyncStrategy()
ZipDriver returns
KeyProviderSyncStrategy.RESET_CANCELLED_KEY.public int getLevel()
ZipEntry.DEFLATED or ZipEntry.BZIP2.
Legal values are Deflater.DEFAULT_COMPRESSION or range from
Deflater#BEST_SPEED to Deflater#BEST_COMPRESSION.
The implementation in the class ZipDriver
returns Deflater#BEST_COMPRESSION.
getLevel in interface ZipOutputStreamParametersDeflater#BEST_COMPRESSIONpublic int getMethod()
ZipEntry does not specify a
compression method.
Legal values are ZipEntry.STORED, ZipEntry.DEFLATED
and ZipEntry.BZIP2.
The implementation in the class ZipDriver
returns ZipEntry#DEFLATED.
getMethod in interface ZipOutputStreamParametersZipEntry#DEFLATEDZipEntry.getMethod()public OptionOutputSocket getOutputSocket(FsController<?> controller, FsEntryName name, BitField<FsOutputOption> options, @CheckForNull Entry template)
options in the following way before
it forwards the call to controller:
FsOutputOption.STORE is set.
FsOutputOption.GROW is set, FsOutputOption.APPEND
gets set too, and FsOutputOption.CACHE gets cleared.
The resulting output socket is then wrapped in a private nested class
for an upcast in newOutputShop(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.socket.OutputSocket<?>, de.schlichtherle.truezip.socket.InputShop<de.schlichtherle.truezip.fs.archive.zip.ZipArchiveEntry>).
Thus, when overriding this method, newOutputShop(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.socket.OutputSocket<?>, de.schlichtherle.truezip.socket.InputShop<de.schlichtherle.truezip.fs.archive.zip.ZipArchiveEntry>) should get
overridden, too.
Otherwise, a class cast exception will get thrown in
newOutputShop(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.socket.OutputSocket<?>, de.schlichtherle.truezip.socket.InputShop<de.schlichtherle.truezip.fs.archive.zip.ZipArchiveEntry>).
getOutputSocket in class FsArchiveDriver<ZipArchiveEntry>protected final IOPool<?> getPool()
getPool in class FsArchiveDriver<ZipArchiveEntry>public boolean getPostambled()
If this method returns true, then a ZIP file is allowed to
contain arbitrary data of arbitrary length as its postamble after the
actual ZIP file data.
Note that searching for an arbitrary length postamble can seriously
degrade the performance when reading a false positive ZIP file, i.e.
an arbitrary file which not compatible to the ZIP File Format
Specification, because then the entire file needs to get searched for
an End Of Central Directory Record (EOCDR) signature.
So this should only be used if self extracting ZIP files with very large
postambles need to get supported.
If this method returns false, then a ZIP file may still have a
postamble, but it must not exceed 64KB size, including the End Of
Central Directory record with the ZIP file comment.
This causes the reading of a false positive ZIP file to fail fast.
The implementation in the class ZipDriver
returns false.
getPostambled in interface ZipFileParameters<ZipArchiveEntry>falsepublic boolean getPreambled()
If this method returns true, then a ZIP file is allowed to
contain arbitrary data as its preamble before the actual ZIP file data.
Self Extracting Archives typically use a preamble to store the
application code that is required to extract the ZIP file contents.
If this method returns false, the a ZIP file must start with
either a Local File Header (LFH) signature,
a ZIP64 End Of Central Directory Record (EOCDR) signature or an End Of
Central Directory Record (EOCDR) signature.
The implementation in the class ZipDriver
returns false.
getPreambled in interface ZipFileParameters<ZipArchiveEntry>falsepublic boolean getRedundantContentSupport()
getRedundantContentSupport in class FsArchiveDriver<ZipArchiveEntry>ZipDriver returns
true because when reading a ZIP file sequentially,
each ZIP entry should "override" any previously read
ZIP entry with an equal name.
This holds true even if the central directory is used to access
the ZIP entries in random order.public boolean getRedundantMetaDataSupport()
getRedundantMetaDataSupport in class FsArchiveDriver<ZipArchiveEntry>ZipDriver returns
true because when reading a ZIP file sequentially,
each ZIP entry should "override" any previously read
ZIP entry with an equal name.
This holds true even if the central directory is used to access
the ZIP entries in random order.public URI mountPointUri(FsModel model)
KeyProviders.
The implementation in the class ZipDriver returns the
expression model.getMountPoint().toHierarchicalUri()
in order to improve the readability of the URI in comparison to the
expression model.getMountPoint().toUri().
model - the file system model.public FsController<?> newController(FsModel model, FsController<?> parent)
The implementation in the class ZipDriver returns the expression
new ZipController(superNewController(model, parent), this).
This method should be overridden in order to call only
superNewController(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.fs.FsController<?>) if and only if you are overriding
zipCryptoParameters(de.schlichtherle.truezip.fs.FsModel, java.nio.charset.Charset), too,
and do not want to use the key manager to resolve passwords,
e.g. for WinZip AES encryption.
newController in class FsArchiveDriver<ZipArchiveEntry>public ZipArchiveEntry newEntry(String name)
ZipEntryFactoryname.newEntry in interface ZipEntryFactory<ZipArchiveEntry>name - the entry name.name.public ZipArchiveEntry newEntry(String name, Entry.Type type, Entry template, BitField<FsOutputOption> mknod) throws CharConversionException
newEntry in class FsArchiveDriver<ZipArchiveEntry>CharConversionExceptionpublic ZipArchiveEntry newEntry(String name, ZipEntry template)
public InputShop<ZipArchiveEntry> newInputShop(FsModel model, InputSocket<?> input) throws IOException
The implementation in the class ZipDriver acquires a read only
file from the given socket and forwards the call to
newInputShop(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.socket.InputSocket<?>).
newInputShop in class FsArchiveDriver<ZipArchiveEntry>IOExceptionprotected InputShop<ZipArchiveEntry> newInputShop(FsModel model, ReadOnlyFile rof) throws IOException
IOExceptionprotected OutputShop<ZipArchiveEntry> newOutputShop(FsModel model, OptionOutputSocket output, @CheckForNull ZipInputShop source) throws IOException
IOExceptionpublic final OutputShop<ZipArchiveEntry> newOutputShop(FsModel model, OutputSocket<?> output, @CheckForNull InputShop<ZipArchiveEntry> source) throws IOException
FsOutputOption.GROW is set
for the given output socket.
If this is the case and the given source is not null,
then it's marked for appending to it.
Then, an output stream is acquired from the given output socket
and the parameters are forwarded to newOutputShop(FsModel, OptionOutputSocket, ZipInputShop)
and the result gets wrapped in a new FsMultiplexedOutputShop
which uses the current getPool().newOutputShop in class FsArchiveDriver<ZipArchiveEntry>IOExceptionprotected OutputShop<ZipArchiveEntry> newOutputShop(FsModel model, OutputStream out, @CheckForNull ZipInputShop source) throws IOException
IOExceptionprivate OutputShop<ZipArchiveEntry> newOutputShop0(FsModel model, OptionOutputSocket output, @CheckForNull ZipInputShop source) throws IOException
IOExceptionprotected boolean process(ZipArchiveEntry input, ZipArchiveEntry output)
true if and only if the content of the given input
target entry needs processing when it gets copied to the given output
target entry.
This method gets called twice (once on each side of a copy operation)
and should return false unless both target entries can mutually
agree on transferring raw (unprocessed) content.
Note that it is an error to compare the properties of the target entries
because this method may get called before the local output target gets
mutated to compare equal with the peer input target!
The implementation in the class ZipDriver returns
local.isEncrypted() || peer.isEncrypted() in order to cover the
typical case that the cipher keys of both targets are not the same.
Note that there is no secure way to explicitly test for this.
input - the input target entry for copying the contents.output - the output target entry for copying the contents.final boolean process(ZipInputShop input, ZipArchiveEntry local, ZipArchiveEntry peer)
final boolean process(ZipOutputShop output, ZipArchiveEntry local, ZipArchiveEntry peer)
public URI resourceUri(FsModel model, String name)
KeyProvider from the given file system model and entry name.
The implementation in the class ZipDriver ignores the given
entry name and just returns the expression mountPointUri(model)
in order to lookup the same key provider for all entries in a ZIP file.
An alternative implementation in a sub-class could return the expression
mountPointUri(model).resolve("/" + name) instead.
model - the file system model.name - the entry name.KeyProvider.protected final FsController<?> superNewController(FsModel model, FsController<?> parent)
FsArchiveDriver.newController(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.fs.FsController<?>) on the FsArchiveDriver
class.
Call this method when overriding newController(de.schlichtherle.truezip.fs.FsModel, de.schlichtherle.truezip.fs.FsController<?>) and you need the
default file system controller chain instead of the implementation in
the class ZipDriver.@CheckForNull protected ZipCryptoParameters zipCryptoParameters(FsModel model, Charset charset)
null if not available.
To enable the use of this method when writing an archive entry with the
client APIs, you must use FsOutputOption.ENCRYPT.
The implementation in the class ZipDriver returns
new KeyManagerZipCryptoParameters(getKeyManagerProvider(), mountPointUri(model), charset).
model - the file system model.charset - charset the character set used for encoding entry names
and the file comment in the ZIP file.null if not available.@CheckForNull final ZipCryptoParameters zipCryptoParameters(ZipInputShop input)
@CheckForNull final ZipCryptoParameters zipCryptoParameters(ZipOutputShop output)
Copyright © 2004-2011 Schlichtherle IT Services. All Rights Reserved.