E
- the type of the ZIP driver entries.@Immutable public abstract class AbstractZipDriver<E extends AbstractZipDriverEntry> extends FsArchiveDriver<E> implements ZipOutputStreamParameters, ZipFileParameters<E>
Sub-classes must be thread-safe and should be immutable!
Constructor and Description |
---|
AbstractZipDriver() |
Modifier and Type | Method and Description |
---|---|
boolean |
check(E local,
ZipInputService<E> input)
Whether or not the content of the given entry shall get
checked/authenticated when reading it.
|
FsController |
decorate(FsController controller)
Decorates the given file system controller.
|
URI |
fileSystemUri(FsModel model,
String name)
A template method for resolving the resource URI which is required to
look up the
KeyProvider for the entry with the given name in the
file system with the given model. |
net.java.truecommons.key.spec.KeyManagerMap |
getKeyManagerMap()
Returns the map of key managers for accessing protected resources
(encryption).
|
int |
getLevel()
Returns the compression level for entries.
|
int |
getMethod()
Returns the default compression method for entries.
|
int |
getOverheadSize()
Returns the number of entries which can be additionally accomodated by
the internal hash map without resizing it.
|
net.java.truecommons.cio.IoBufferPool |
getPool()
Returns the pool for allocating temporary I/O buffers.
|
boolean |
getPostambled()
Returns the flag for supporting postambles of arbitrary length.
|
boolean |
getPreambled()
Returns the flag for supporting preambles.
|
boolean |
getRedundantContentSupport()
Returns
true if and only if the archive files produced by this
archive driver may contain redundant archive entry contents. |
boolean |
getRedundantMetaDataSupport()
Returns
true if and only if the archive files produced by this
archive driver may contain redundant archive entry meta data. |
URI |
mountPointUri(FsModel model)
A template method for resolving the resource URI which is required to
look up the
KeyProvider for the mount point of the file system
with the given model. |
E |
newEntry(net.java.truecommons.shed.BitField<FsAccessOption> options,
String name,
net.java.truecommons.cio.Entry.Type type,
net.java.truecommons.cio.Entry template)
Returns a new entry for the given name.
|
abstract E |
newEntry(String name)
Returns a new ZIP driver entry with the given
name . |
abstract E |
newEntry(String name,
ZipEntry template)
Returns a new ZIP driver entry with the given
name and all
other properties copied from the given template. |
protected ZipInputService<E> |
newInput(FsModel model,
FsInputSocketSource source)
Creates a new input service for reading archive entries for the given
model from the target archive file referenced by source . |
protected net.java.truecommons.cio.OutputService<E> |
newOutput(FsModel model,
FsOutputSocketSink sink,
net.java.truecommons.cio.InputService<E> input)
Creates a new input service for writing archive entries for the given
model to the target archive file referenced by sink . |
protected ZipInputService<E> |
newZipInput(FsModel model,
FsInputSocketSource source) |
protected boolean |
rdc(AbstractZipDriverEntry input,
AbstractZipDriverEntry output)
Returns
true if and only if the content of the given input
target entry is eligible for Raw Data Copying (RDC). |
protected FsOutputSocketSink |
sink(net.java.truecommons.shed.BitField<FsAccessOption> options,
FsController controller,
FsNodeName name)
This implementation modifies
options in the following way before
it forwards the call to controller :
FsAccessOption.STORE is set. |
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. |
checkEncodable, getCharset, isArchiveDriver, newController, newEntry, newInput, newOutput, normalize, source, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getCharset
public boolean check(E local, @WillNotClose ZipInputService<E> input)
true
and the check fails, then an
IOException
gets thrown.local
- the entry to test.input
- the origin of the entry.entry.isEncrypted()
.public FsController decorate(FsController controller)
The implementation in the class ZipDriver
decorates the given controller with a package private
controller which keeps track of the AES PBE parameters, e.g. the encryption passwords.
This method should be overridden in order to return just controller
if and only if you are overriding
zipCryptoParameters(FsModel, Charset)
, too, and do not want to use a locatable key manager to resolve
passwords for WinZip AES encryption.
decorate
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
controller
- the file system controller to decorate.FsArchiveDriver
unconditionally returns controller
.public URI fileSystemUri(FsModel model, String name)
KeyProvider
for the entry with the given name in the
file system with the given model.
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
.public net.java.truecommons.key.spec.KeyManagerMap getKeyManagerMap()
This is an immutable property - multiple calls must return the same object.
KeyManagerMapLocator.SINGLETON
, as by the implementation
in the class ZipDriver
.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 ZipOutputStreamParameters
Deflater#BEST_COMPRESSION
public 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 ZipOutputStreamParameters
ZipEntry#DEFLATED
ZipEntry.getMethod()
public int getOverheadSize()
The implementation in the class ZipDriver
returns Maps#OVERHEAD_SIZE
.
getOverheadSize
in interface ZipOutputStreamParameters
Maps#OVERHEAD_SIZE
public net.java.truecommons.cio.IoBufferPool getPool()
This is an immutable property - multiple calls must return the same object.
The implementation in the class AbstractZipDriver
returns
IoBufferPoolLocator.SINGLETON.get()
.
getPool
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
public boolean getPostambled()
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 is 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.
A valid use case are self extracting ZIP files with very large
postambles to host the extraction code.
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<E extends AbstractZipDriverEntry>
false
public boolean getPreambled()
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
, then 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<E extends AbstractZipDriverEntry>
false
public boolean getRedundantContentSupport()
true
if and only if the archive files produced by this
archive driver may contain redundant archive entry contents.
If the return value is true
, then an archive file may contain
redundant archive entry contents, but only the last contents written
should get used when reading the archive file.
This is an immutable property - multiple calls must return the same value.
The default value of this property is false
as defined by the
implementation in the class FsArchiveDriver
.
getRedundantContentSupport
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
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()
true
if and only if the archive files produced by this
archive driver may contain redundant archive entry meta data.
If the return value is true
, then an archive file may contain
redundant archive entry meta data, but only the last meta data written
should get used when reading the archive file.
This usually implies the existence of a central directory in the
resulting archive file.
This is an immutable property - multiple calls must return the same value.
The default value of this property is false
as defined by the
implementation in the class FsArchiveDriver
.
getRedundantMetaDataSupport
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
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)
KeyProvider
for the mount point of the file system
with the given model.
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().getUri()
.
model
- the file system model.public E newEntry(net.java.truecommons.shed.BitField<FsAccessOption> options, String name, net.java.truecommons.cio.Entry.Type type, @CheckForNull net.java.truecommons.cio.Entry template)
FsArchiveDriver
entry name
for their particular requirements.newEntry
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
options
- when called from FsController.make(net.java.truecommons.shed.BitField<net.java.truevfs.kernel.spec.FsAccessOption>, net.java.truevfs.kernel.spec.FsNodeName, net.java.truecommons.cio.Entry.Type, net.java.truecommons.cio.Entry)
, this is its
options
parameter, otherwise it's typically an empty set.name
- the entry name.type
- the entry type.template
- if not null
, then the new entry shall inherit
as much properties from this entry as possible - with the
exception of its name and type.FsArchiveDriver.newEntry(String, Entry.Type, Entry)
public abstract E newEntry(String name)
name
.newEntry
in interface ZipEntryFactory<E extends AbstractZipDriverEntry>
name
- the entry name.public abstract E newEntry(String name, ZipEntry template)
name
and all
other properties copied from the given template.name
- the entry name.template
- the template entry.protected final ZipInputService<E> newInput(FsModel model, FsInputSocketSource source) throws IOException
FsArchiveDriver
model
from the target archive file referenced by source
.newInput
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
model
- the file system model.source
- the source for reading the target archive file.IOException
- on any I/O error.FsArchiveDriver.newInput(FsModel, BitField, FsController, FsNodeName)
@CreatesObligation protected net.java.truecommons.cio.OutputService<E> newOutput(FsModel model, FsOutputSocketSink sink, @CheckForNull @WillNotClose net.java.truecommons.cio.InputService<E> input) throws IOException
FsArchiveDriver
model
to the target archive file referenced by sink
.newOutput
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
model
- the file system model.sink
- the sink for writing the target archive file.input
- the nullable InputService
for the target archive
file.
If not null
, then the target archive file is going to
get updated.
This parameter is guaranteed to be the product of this driver's
factory method
FsArchiveDriver.newInput(FsModel, BitField, FsController, FsNodeName)
.IOException
- on any I/O error.FsArchiveDriver.newOutput(FsModel, BitField, FsController, FsNodeName, InputService)
@CreatesObligation protected ZipInputService<E> newZipInput(FsModel model, FsInputSocketSource source) throws IOException
IOException
protected boolean rdc(AbstractZipDriverEntry input, AbstractZipDriverEntry output)
true
if and only if the content of the given input
target entry is eligible for Raw Data Copying (RDC).
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 output target
entry gets mutated to compare equal with the input target entry!
The implementation in the class ZipDriver
returns
!local.isEncrypted() && !remote.isEncrypted()
in order to cover
the typical case that the cipher keys of both targets are not the same.
Note that there is no safe way to explicitly test for this.
input
- the input target entry for copying the contents.output
- the output target entry for copying the contents.protected FsOutputSocketSink sink(net.java.truecommons.shed.BitField<FsAccessOption> options, FsController controller, FsNodeName name)
options
in the following way before
it forwards the call to controller
:
FsAccessOption.STORE
is set.
FsAccessOption.GROW
is set, then
FsAccessOption.APPEND
gets set, too, and
FsAccessOption.CACHE
gets cleared.
The resulting output socket is then wrapped in a private nested class
for an upcast in newOutput(net.java.truevfs.kernel.spec.FsModel, net.java.truevfs.kernel.spec.FsOutputSocketSink, net.java.truecommons.cio.InputService<E>)
.
Thus, when overriding this method, newOutput(net.java.truevfs.kernel.spec.FsModel, net.java.truevfs.kernel.spec.FsOutputSocketSink, net.java.truecommons.cio.InputService<E>)
should get
overridden, too.
Otherwise, a class cast exception will be thrown in newOutput(net.java.truevfs.kernel.spec.FsModel, net.java.truevfs.kernel.spec.FsOutputSocketSink, net.java.truecommons.cio.InputService<E>)
.
sink
in class FsArchiveDriver<E extends AbstractZipDriverEntry>
options
- the options for accessing the file system node.controller
- the controller to use for writing an artifact of this
driver.name
- the node name.FsArchiveDriver.newOutput(FsModel, BitField, FsController, FsNodeName, InputService)
@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 FsAccessOption.ENCRYPT
.
The implementation in the class ZipDriver
returns
new KeyManagerZipCryptoParameters(this, 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.Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.