Class TLcdTarModelListDecoder

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

public class TLcdTarModelListDecoder extends Object implements ILcdModelDecoder, ILcdInputStreamFactoryCapable
This ILcdModelDecoder allows to decode entries in tar 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 tar 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 tar file is a composed name. It is formatted as [tar source name]![entry name]. Since the decoding of the entries in the tar 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 tar file before starting the decode. This is something most decoders don't do by default. However, many decoders (and model reference decoders) allow to set an ILcdInputStreamFactory for creating an input stream from a source name. The TLcdTarInputStreamFactory can then be used as ILcdInputStreamFactory. It interprets the source name correctly and positions the stream on the correct entry in the tar 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

    • TLcdTarModelListDecoder

      public TLcdTarModelListDecoder(ILcdModelDecoder[] aModelDecoders)
      Constructs a TLcdTarModelListDecoder from a list of ILcdModelDecoder objects to try for decoding the tar entries.
      Parameters:
      aModelDecoders - an array of ILcdModelDecoder to try for decoding the tar 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.
      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 "tar" or "gz".
      See Also:
    • decode

      public ILcdModel decode(String aSourceName) throws IOException
      Decodes all entries of the specified tar 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 tar 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: