Class TLcdZipModelListDecoder
- All Implemented Interfaces:
ILcdInputStreamFactoryCapable
,ILcdModelDecoder
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
.
- Since:
- 7.0.17
-
Constructor Summary
ConstructorDescriptionTLcdZipModelListDecoder
(ILcdModelDecoder[] aModelDecoders) Constructs aTLcdZipModelListDecoder
from a list ofILcdModelDecoder
objects to try for decoding the zip entries. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canDecodeSource
(String aSourceName) Checks if this decoder can decode the specified source.Decodes all entries of the specified zip file with the registered decoders, and returns the decoded models as a model list.Returns the display name.Returns the input stream factory that will be used for creating input streams from source names.boolean
Returns whether anILcdModelTreeNode
or aTLcdModelList
is created when decoding a source.boolean
Deprecated.This method has been deprecated.static void
setClassTraceOn
(boolean aClassTraceOn) Deprecated.This method has been deprecated.void
setCreateModelTreeNodes
(boolean aCreateModelTreeNodes) Specifies whether anILcdModelTreeNode
or aTLcdModelList
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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.model.ILcdModelDecoder
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
-
Constructor Details
-
TLcdZipModelListDecoder
Constructs aTLcdZipModelListDecoder
from a list ofILcdModelDecoder
objects to try for decoding the zip entries.- Parameters:
aModelDecoders
- an array ofILcdModelDecoder
to try for decoding the zip entries.
-
-
Method Details
-
setInputStreamFactory
Sets the input stream factory that will be used for creating input streams from source names. Note that the input stream factory must not automatically unzip its input, as is done by default by the
(see its methodTLcdInputStreamFactory
). This decoder will perform the unzipping.setUnzipAutomatically(boolean)
- Specified by:
setInputStreamFactory
in interfaceILcdInputStreamFactoryCapable
- Parameters:
aInputStreamFactory
- theILcdInputStreamFactory
for creating input streams from source names.
-
getInputStreamFactory
Returns the input stream factory that will be used for creating input streams from source names.- Specified by:
getInputStreamFactory
in interfaceILcdInputStreamFactoryCapable
- Returns:
- the
ILcdInputStreamFactory
for creating input streams from source names.
-
setClassTraceOn
public static void setClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for all instances of this class. If the argument istrue
then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.- Parameters:
aClassTraceOn
- if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
-
setTraceOn
public void setTraceOn(boolean aTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for this class instance. Calling this method with eithertrue
orfalse
as argument automatically turns off tracing for all other class instances for whichsetTraceOn
has not been called. If the argument isfalse
then only the informative, warning and error log messages are recorded.- Parameters:
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.
-
isTraceOn
public boolean isTraceOn()Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Returnstrue
if tracing is enabled for this class.- Returns:
- true if tracing is enabled for this class, false otherwise.
-
setCreateModelTreeNodes
public void setCreateModelTreeNodes(boolean aCreateModelTreeNodes) Specifies whether anILcdModelTreeNode
or aTLcdModelList
should be created when decoding a source.- Parameters:
aCreateModelTreeNodes
-true
if anILcdModelTreeNode
should be created,false
if aTLcdModelList
should be created.
-
isCreateModelTreeNodes
public boolean isCreateModelTreeNodes()Returns whether anILcdModelTreeNode
or aTLcdModelList
is created when decoding a source. The default isfalse
, for aTLcdModelList
.- Returns:
true
if anILcdModelTreeNode
is created when decoding a source,false
if aTLcdModelList
is be created.
-
getDisplayName
Returns the display name.- Specified by:
getDisplayName
in interfaceILcdModelDecoder
- Returns:
- the display name.
-
canDecodeSource
Checks if this decoder can decode the specified source.- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- the data source to be verified; typically a file name or a URL.- Returns:
true
if sourceaString
has extension "zip" or "gz".- See Also:
-
decode
Decodes all entries of the specified zip file with the registered decoders, and returns the decoded models as a model list.- Specified by:
decode
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- name of the zip file.- Returns:
- the decoded model list.
- Throws:
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); } }
- See Also:
-