public class TLcdZipModelListDecoder extends Object implements ILcdModelDecoder, ILcdInputStreamFactoryCapable
ILcdModelDecoder
allows to decode entries in zip files.
The decoder contains a specified list of ILcdModelDecoder
instances that will perform the actual decoding of the entries.
The decode
method decodes each entry of the given zip file,
using the first decoder whose canDecodeSource
method returns
true
. If a decoder is found, it is used to decode the entry
and the resulting model is added to the model list. If no decoder is found,
the entry is skipped. Note that directory entries are always skipped.
The source name of an entry in a zip file is a composed name.
It is formatted as [zip source name]![entry name].
Since the decoding of the entries in the zip file is delegated to the
decoders specified in the constructor, these decoders must interpret that
source name correctly and position on the entry in the zip file before
starting to decode. This is something most decoders don't do by default.
However, many decoders (and model reference decoders) allow to set a
ILcdInputStreamFactory
for creating an input stream from a
source name. The TLcdZipInputStreamFactory
can then be used as
ILcdInputStreamFactory
. It interprets the source name correctly
and positions the stream on the correct entry in the zip file.
The resulting ILcdModel
is a TLcdModelList
containing the models of the decoded entries. If all models implement
ILcd2DBoundsIndexedModel
, the resulting model is a
TLcd2DBoundsIndexedModelList
. Optionally, if the property
createModelTreeNodes
is set, the resulting model
is an ILcdModelTreeNode
.
Constructor and Description |
---|
TLcdZipModelListDecoder(ILcdModelDecoder[] aModelDecoders)
Constructs a
TLcdZipModelListDecoder from a list of ILcdModelDecoder objects
to try for decoding the zip entries. |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeSource(String aSourceName)
Checks if this decoder can decode the specified source.
|
ILcdModel |
decode(String aSourceName)
Decodes all entries of the specified zip file with the registered decoders,
and returns the decoded models as a model list.
|
String |
getDisplayName()
Returns the display name.
|
ILcdInputStreamFactory |
getInputStreamFactory()
Returns the input stream factory that will be used for creating input
streams from source names.
|
boolean |
isCreateModelTreeNodes()
Returns whether an
ILcdModelTreeNode or a TLcdModelList is
created when decoding a source. |
boolean |
isTraceOn()
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
static void |
setClassTraceOn(boolean aClassTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
void |
setCreateModelTreeNodes(boolean aCreateModelTreeNodes)
Specifies whether an
ILcdModelTreeNode or a TLcdModelList
should be created when decoding a source. |
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Sets the input stream factory that will be used for creating input streams
from source names.
|
void |
setTraceOn(boolean aTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
public TLcdZipModelListDecoder(ILcdModelDecoder[] aModelDecoders)
TLcdZipModelListDecoder
from a list of ILcdModelDecoder
objects
to try for decoding the zip entries.aModelDecoders
- an array of ILcdModelDecoder
to try for decoding the zip entries.public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
TLcdInputStreamFactory
(see its method
setUnzipAutomatically(boolean)
).
This decoder will perform the unzipping.setInputStreamFactory
in interface ILcdInputStreamFactoryCapable
aInputStreamFactory
- the ILcdInputStreamFactory
for creating input streams from source names.public ILcdInputStreamFactory getInputStreamFactory()
getInputStreamFactory
in interface ILcdInputStreamFactoryCapable
ILcdInputStreamFactory
for creating input streams from source names.public static void setClassTraceOn(boolean aClassTraceOn)
true
then all log messages are recorded, otherwise only
the informative, warning and error messages are recorded.aClassTraceOn
- if true then all log messages are recorded,
otherwise only the informative, warning and error messages are recorded.public void setTraceOn(boolean aTraceOn)
true
or false
as argument automatically turns
off tracing for all other class instances for which
setTraceOn
has not been called.
If the argument is false
then only the informative, warning
and error log messages are recorded.aTraceOn
- if true then all log messages are recorded for this
instance. If false, then only the informative, warning and
error log messages are recorded.public boolean isTraceOn()
true
if tracing is enabled for this class.public void setCreateModelTreeNodes(boolean aCreateModelTreeNodes)
ILcdModelTreeNode
or a TLcdModelList
should be created when decoding a source.aCreateModelTreeNodes
- true
if an ILcdModelTreeNode
should be created,
false
if a TLcdModelList
should be created.public boolean isCreateModelTreeNodes()
ILcdModelTreeNode
or a TLcdModelList
is
created when decoding a source. The default is false
, for
a TLcdModelList
.true
if an ILcdModelTreeNode
is created when
decoding a source, false
if a TLcdModelList
is be created.public String getDisplayName()
getDisplayName
in interface ILcdModelDecoder
public boolean canDecodeSource(String aSourceName)
canDecodeSource
in interface ILcdModelDecoder
aSourceName
- the data source to be verified; typically a file name or a URL.true
if source aString
has extension "zip" or "gz".ILcdModelDecoder.decode(String)
,
ILcdModelDecoder.decodeModelMetadata(String)
public ILcdModel decode(String aSourceName) throws IOException
decode
in interface ILcdModelDecoder
aSourceName
- name of the zip file.IOException
- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost
always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException,
IllegalArgumentException, ...) on unexpected places, implementations are advised to catch
RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated
in the code snippet below.
public ILcdModel decode( String aSourceName ) throws IOException {
try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) {
// Perform decoding ...
} catch (RuntimeException e) {
throw new IOException(e);
}
}
InterruptedIOException
- When the thread on which this method is called is interrupted: it is recommended to stop the decoding
and throw an InterruptedIOException
.
This same exception can also be used if the decoder shows UI to the user, and the user cancels the decoding
through the UI.ILcdModelDecoder.canDecodeSource(String)