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
ConstructorsConstructorDescriptionTLcdZipModelListDecoder(ILcdModelDecoder[] aModelDecoders) Constructs aTLcdZipModelListDecoderfrom a list ofILcdModelDecoderobjects to try for decoding the zip entries. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDecodeSource(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.booleanReturns whether anILcdModelTreeNodeor aTLcdModelListis created when decoding a source.booleanDeprecated.This method has been deprecated.static voidsetClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated.voidsetCreateModelTreeNodes(boolean aCreateModelTreeNodes) Specifies whether anILcdModelTreeNodeor aTLcdModelListshould be created when decoding a source.voidsetInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory) Sets the input stream factory that will be used for creating input streams from source names.voidsetTraceOn(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, waitMethods inherited from interface com.luciad.model.ILcdModelDecoder
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
-
Constructor Details
-
TLcdZipModelListDecoder
Constructs aTLcdZipModelListDecoderfrom a list ofILcdModelDecoderobjects to try for decoding the zip entries.- Parameters:
aModelDecoders- an array ofILcdModelDecoderto 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:
setInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Parameters:
aInputStreamFactory- theILcdInputStreamFactoryfor 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:
getInputStreamFactoryin interfaceILcdInputStreamFactoryCapable- Returns:
- the
ILcdInputStreamFactoryfor 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 istruethen 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 eithertrueorfalseas argument automatically turns off tracing for all other class instances for whichsetTraceOnhas not been called. If the argument isfalsethen 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.Returnstrueif 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 anILcdModelTreeNodeor aTLcdModelListshould be created when decoding a source.- Parameters:
aCreateModelTreeNodes-trueif anILcdModelTreeNodeshould be created,falseif aTLcdModelListshould be created.
-
isCreateModelTreeNodes
public boolean isCreateModelTreeNodes()Returns whether anILcdModelTreeNodeor aTLcdModelListis created when decoding a source. The default isfalse, for aTLcdModelList.- Returns:
trueif anILcdModelTreeNodeis created when decoding a source,falseif aTLcdModelListis be created.
-
getDisplayName
Returns the display name.- Specified by:
getDisplayNamein interfaceILcdModelDecoder- Returns:
- the display name.
-
canDecodeSource
Checks if this decoder can decode the specified source.- Specified by:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
aSourceName- the data source to be verified; typically a file name or a URL.- Returns:
trueif sourceaStringhas 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:
decodein 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:
-