Class TLcdZipModelListDecoder

java.lang.Object
com.luciad.model.TLcdZipModelListDecoder
All Implemented Interfaces:
ILcdInputStreamFactoryCapable, ILcdModelDecoder

public class TLcdZipModelListDecoder extends Object implements ILcdModelDecoder, ILcdInputStreamFactoryCapable
This 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 Details

    • TLcdZipModelListDecoder

      public TLcdZipModelListDecoder(ILcdModelDecoder[] aModelDecoders)
      Constructs a TLcdZipModelListDecoder from a list of ILcdModelDecoder objects to try for decoding the zip entries.
      Parameters:
      aModelDecoders - an array of ILcdModelDecoder to try for decoding the zip entries.
  • Method Details

    • setInputStreamFactory

      public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
      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 TLcdInputStreamFactory (see its method setUnzipAutomatically(boolean)). This decoder will perform the unzipping.
      Specified by:
      setInputStreamFactory in interface ILcdInputStreamFactoryCapable
      Parameters:
      aInputStreamFactory - the ILcdInputStreamFactory for creating input streams from source names.
    • getInputStreamFactory

      public ILcdInputStreamFactory getInputStreamFactory()
      Returns the input stream factory that will be used for creating input streams from source names.
      Specified by:
      getInputStreamFactory in interface ILcdInputStreamFactoryCapable
      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 is true 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 either 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.
      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.
      Returns true 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 an ILcdModelTreeNode or a TLcdModelList should be created when decoding a source.
      Parameters:
      aCreateModelTreeNodes - true if an ILcdModelTreeNode should be created, false if a TLcdModelList should be created.
    • isCreateModelTreeNodes

      public boolean isCreateModelTreeNodes()
      Returns whether an ILcdModelTreeNode or a TLcdModelList is created when decoding a source. The default is false, for a TLcdModelList.
      Returns:
      true if an ILcdModelTreeNode is created when decoding a source, false if a TLcdModelList is be created.
    • getDisplayName

      public String getDisplayName()
      Returns the display name.
      Specified by:
      getDisplayName in interface ILcdModelDecoder
      Returns:
      the display name.
    • canDecodeSource

      public boolean canDecodeSource(String aSourceName)
      Checks if this decoder can decode the specified source.
      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aSourceName - the data source to be verified; typically a file name or a URL.
      Returns:
      true if source aString has extension "zip" or "gz".
      See Also:
    • decode

      public ILcdModel decode(String aSourceName) throws IOException
      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 interface ILcdModelDecoder
      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: