Package com.luciad.io

Class TLcdStatusOutputStreamFactory

java.lang.Object
com.luciad.io.TLcdStatusOutputStreamFactory
All Implemented Interfaces:
ILcdOutputStreamFactory

public class TLcdStatusOutputStreamFactory extends Object implements ILcdOutputStreamFactory

This ILcdOutputStreamFactory creates OutputStreams that report writing progress by firing TLcdStatusEvents to the attached ILcdStatusListeners. It produces indeterminate progress events, as no prediction about the total data size is available. It can be used in combination with most ILcdModelEncoder implementations, to conveniently inform end users about encoding progress. An ILcdStatusListener still needs to be added that actually informs the end user, for example by using a JProgressBar.

It uses a given ILcdOutputStreamFactory to create the actual OutputStream. The messages of the TLcdStatusEvents can be fully customized. They support to include the destination name (e.g. file name) and the kilobytes that are already written.

A list of destination names that must be excluded can be provided. If a given destination name is on the exclude list, a regular OutputStream 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).

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

Since:
8.1
  • Constructor Details

    • TLcdStatusOutputStreamFactory

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

      public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
      Creates a new TLcdStatusOutputStreamFactory that delegates the creation of the actual OutputStream to the given ILcdOutputStreamFactory.
      Parameters:
      aOutputStreamFactory - The factory to delegate the creation of the actual OutputStreams to.
    • TLcdStatusOutputStreamFactory

      public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, String aMessage)
      Creates a new TLcdStatusOutputStreamFactory for the given ILcdOutputStreamFactory that produces TLcdStatusEvents with the given message.
      Parameters:
      aOutputStreamFactory - The factory to delegate the creation of the actual OutputStreams to.
      aMessage - Message to be used in the TLcdStatusEvents. {0} is replaced with the destination name (as provided to createOutputStream), {1} is replaced with the kilobytes that are written (the KB unit sign is added automatically). 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:
      
       "Writing ''{0}'' ... {1}"
       
      would result in:
      
       "Writing 'someFile.shp' ... 100KB"
       
      The message:
      
       "Writing [{0}] ..."
       
      would result in:
      
       "Writing [someFile.shp] ..."
       
    • TLcdStatusOutputStreamFactory

      public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aMessageFormat)
      Creates a new TLcdStatusOutputStreamFactory for the given ILcdOutputStreamFactory that produces TLcdStatusEvents with messages formatted by the given message format.
      Parameters:
      aOutputStreamFactory - The factory to delegate the creation of the actual OutputStreams 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 destination name as provided in createOutputStream, the second parameter is the kilobytes that are already written as a Double. One could for example create a usable format like this:
      
       MessageFormat mf = new MessageFormat( "Writing [{0}] ... {1}" );
       mf.setFormat( 1, new DecimalFormat( "###,###,###,###KB" ) );
       
      or like this:
      
       new MessageFormat( "Writing [{0}] ..." )
       
    • TLcdStatusOutputStreamFactory

      public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat)
      Creates a new TLcdStatusOutputStreamFactory for the given ILcdOutputStreamFactory that produces TLcdStatusEvents with messages formatted by the given message formats. All messages are defined identical to that of TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory, java.text.Format).
      Parameters:
      aOutputStreamFactory - The factory to delegate the creation of the actual OutputStreams 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 TLcdStatusOutputStreamFactory. As a result, all OutputStreams created afterwards inform this listener about the made progress.
      Parameters:
      aStatusListener - The listener to add.
    • removeStatusEventListener

      public void removeStatusEventListener(ILcdStatusListener aStatusListener)
      Removes the given ILcdStatusListener from this TLcdStatusOutputStreamFactory.
      Parameters:
      aStatusListener - The listener to remove.
    • getExcludedDestinations

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

      public void setExcludedDestinations(String[] aExcludedDestinations)
      Sets the list of destination names (as given to createOutputStream) that must be excluded. If a destination name is excluded, a regular OutputStream 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:
      aExcludedDestinations - 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 destination 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:
    • createOutputStream

      public OutputStream createOutputStream(String aDestinationName) throws IOException
      Description copied from interface: ILcdOutputStreamFactory
      Creates an output stream to a given destination.
      Specified by:
      createOutputStream in interface ILcdOutputStreamFactory
      Parameters:
      aDestinationName - an accessible destination.
      Returns:
      an OutputStream to the destination.
      Throws:
      IOException - when the destination is non accessible.