Package com.luciad.io

Class TLcdStatusInputStreamFactory

java.lang.Object
com.luciad.io.TLcdStatusInputStreamFactory
All Implemented Interfaces:
ILcdInputStreamFactory, ILcdStatusSource

public class TLcdStatusInputStreamFactory extends Object implements ILcdInputStreamFactory, ILcdStatusSource

This ILcdInputStreamFactory creates InputStreams that report reading progress by firing TLcdStatusEvents to the attached ILcdStatusListeners. It can be used in combination with most ILcdModelDecoder implementations, to conveniently inform end users about decoding progress. An ILcdStatusListener still needs to be added that actually informs the end user, for example by using a JProgressBar.

It uses a given ILcdInputStreamFactory to create the actual InputStream. The messages of the TLcdStatusEvents can be fully customized. They support to include the source name (e.g. file name) and the percentage of completion.

A list of source names that must be excluded can be provided. If a given source name is on the exclude list, a regular InputStream is created instead of a special stream that reports status. This can be convenient to for example avoid reporting progress about an accompanying file, such as a .ref (Luciad reference) or a .dbf file (attributes of a shp file).

This can be also used to not wrap the input stream for specific usages. For example when support for a data format requires random files access, such as TIFF.

This factory excludes the following format(s) by default:

  • *.tiff?

Calling Thread.interrupt() will make the streams created by this factory throw an InterruptedIOException upon next (read) access. It also clears the threads interrupted flag.

Limitations

It assumes the InputStream.available() method of the InputStream created by the given ILcdInputStreamFactory returns the total size of the stream to read, in order to correctly predict the percentage of completion. If 0 is returned, indeterminate TLcdStatusEvents are fired. If the initially returned size was too small, it will switch to indeterminate progress as soon as this becomes apparent.

Since:
8.1
  • Constructor Details

    • TLcdStatusInputStreamFactory

      public TLcdStatusInputStreamFactory()
      Creates a new TLcdStatusInputStreamFactory, ready to use. ILcdStatusListener(s) need to be added to make it useful.
    • TLcdStatusInputStreamFactory

      public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
      Creates a new TLcdStatusInputStreamFactory that delegates the creation of the actual InputStream to the given ILcdInputStreamFactory.
      Parameters:
      aInputStreamFactory - The factory to delegate the creation of the actual InputStreams to.
    • TLcdStatusInputStreamFactory

      public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, String aMessage)
      Creates a new TLcdStatusInputStreamFactory for the given ILcdInputStreamFactory that produces TLcdStatusEvents with the given message.
      Parameters:
      aInputStreamFactory - The factory to delegate the creation of the actual InputStreams to.
      aMessage - Message to be used in the TLcdStatusEvents. {0} is replaced with the source name (as provided to createInputStream), {1} is replaced with the percentage of completion (the % sign is added automatically), or with '?' if no prediction of completion is available. It is allowed to omit one or both of these replacements. Note that the message is used as a pattern for MessageFormat, so for example single quotes need to be escaped by writing them twice. For example, the message:
       "Reading ''{0}'' ... {1} done"
       
      would result in:
       "Reading 'someFile.shp' ... 5% done"
       
      The message:
       "Reading [{0}] ..."
       
      would result in:
       "Reading [someFile.shp] ..."
       
    • TLcdStatusInputStreamFactory

      public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aMessageFormat)
      Creates a new TLcdStatusInputStreamFactory for the given ILcdInputStreamFactory that produces TLcdStatusEvents with messages formatted by the given message format.
      Parameters:
      aInputStreamFactory - The factory to delegate the creation of the actual InputStreams to.
      aMessageFormat - The Format used to create the messages for the TLcdStatusEvents. When formatting, an array of two parameters is given. One String that equals the source name as provided in createInputStream, the second parameter is the percentage of completion as a Double in the interval [0,1]. One could for example create a usable format like this:
      
       MessageFormat mf = new MessageFormat( "Reading [{0}] ... {1} done" );
       mf.setFormat( 1, NumberFormat.getPercentInstance() );
       
      or like this:
      
       new MessageFormat( "Reading [{0}] ..." )
       
    • TLcdStatusInputStreamFactory

      public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat)
      Creates a new TLcdStatusInputStreamFactory for the given ILcdInputStreamFactory that produces TLcdStatusEvents with messages formatted by the given message formats. All messages are defined identical to that of TLcdStatusInputStreamFactory(ILcdInputStreamFactory, java.text.Format).
      Parameters:
      aInputStreamFactory - The factory to delegate the creation of the actual InputStreams to.
      aStartBusyMessageFormat - The Format used to create the message for the START_BUSY TLcdStatusEvent. The message is defined identical as in the other constructor.
      aProgressMessageFormat - The Format used to create the message for the PROGRESS TLcdStatusEvent. The message is defined identical as in the other constructor.
      aEndBusyMessageFormat - The Format used to create the message for the END_BUSY TLcdStatusEvent. The message is defined identical as in the other constructor.
  • Method Details

    • addStatusEventListener

      public void addStatusEventListener(ILcdStatusListener aStatusListener)
      Adds the given ILcdStatusListener to this TLcdStatusInputStreamFactory. As a result, all InputStreams created afterwards inform this listener about the made progress.
      Parameters:
      aStatusListener - The listener to add.
      See Also:
    • removeStatusEventListener

      public void removeStatusEventListener(ILcdStatusListener aStatusListener)
      Removes the given ILcdStatusListener from this TLcdStatusInputStreamFactory.
      Parameters:
      aStatusListener - The listener to remove.
      See Also:
    • addStatusListener

      public void addStatusListener(ILcdStatusListener aListener)
      Description copied from interface: ILcdStatusSource

      Registers the given listener so it will receive status events from this source.

      In case you need to register a listener which keeps a reference to an object with a shorter life-time than this status source, you can use a ALcdWeakStatusListener instance as status listener.

      Specified by:
      addStatusListener in interface ILcdStatusSource
      Parameters:
      aListener - The listener to be notified when the status has changed.
    • removeStatusListener

      public void removeStatusListener(ILcdStatusListener aListener)
      Description copied from interface: ILcdStatusSource
      Removes the specified listener so it is no longer notified.
      Specified by:
      removeStatusListener in interface ILcdStatusSource
      Parameters:
      aListener - The listener to remove.
    • getExcludedSources

      public String[] getExcludedSources()
      Returns the list of source names to exclude from creating streams that produce TLcdStatusEvents.
      Returns:
      the list of source names to exclude from creating streams that produce TLcdStatusEvents.
      See Also:
    • setExcludedSources

      public void setExcludedSources(String[] aExcludedSources)
      Sets the list of source names (as given to createInputStream) that must be excluded. If a source name is excluded, a regular InputStream is created, instead of one that produces TLcdStatusEvents. This can be convenient to for example avoid reporting progress about an accompanying file, such as a .ref (Luciad reference) or a .dbf file (attributes of a shp file).

      Parameters:
      aExcludedSources - The array of regular expressions (case insensitive) that makes up the exclude list. It must not be null. Use for example this array to exclude all source names that end with .ref or with .dbf:
      
       new String[]{".*\\.ref", ".*\\.dbf"}
       
      The default is an empty array. See java.util.regex.Pattern for a description of regular expressions.
    • isBlockingHint

      public boolean isBlockingHint()

      Returns the blocking hint that is present in the TLcdStatusEvents that are fired to the associated ILcdStatusListeners.

      Default is true.

      Returns:
      the blocking hint.
      See Also:
    • setBlockingHint

      public void setBlockingHint(boolean aBlockingHint)

      Sets the blocking hint that is present in the TLcdStatusEvents that are fired to the associated ILcdStatusListeners.

      Parameters:
      aBlockingHint - True to suggest blocking, false to suggest non-blocking.
      See Also:
    • createInputStream

      public InputStream createInputStream(String aSourceName) throws IOException
      Description copied from interface: ILcdInputStreamFactory
      Creates an InputStream from aSource.
      Specified by:
      createInputStream in interface ILcdInputStreamFactory
      Parameters:
      aSourceName - an accessible data source.
      Returns:
      an InputStream from the data source.
      Throws:
      IOException - when aSource is not accepted by canCreateInputStream or is not accessible.
      See Also: