Class TLcdStatusOutputStreamFactory
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCreates a newTLcdStatusOutputStreamFactory, ready to use.TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory) Creates a newTLcdStatusOutputStreamFactorythat delegates the creation of the actualOutputStreamto the givenILcdOutputStreamFactory.TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, String aMessage) Creates a newTLcdStatusOutputStreamFactoryfor the givenILcdOutputStreamFactorythat producesTLcdStatusEvents with the given message.TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aMessageFormat) Creates a newTLcdStatusOutputStreamFactoryfor the givenILcdOutputStreamFactorythat producesTLcdStatusEvents with messages formatted by the given message format.TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat) Creates a newTLcdStatusOutputStreamFactoryfor the givenILcdOutputStreamFactorythat producesTLcdStatusEvents with messages formatted by the given message formats. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStatusEventListener(ILcdStatusListener aStatusListener) Adds the givenILcdStatusListenerto thisTLcdStatusOutputStreamFactory.createOutputStream(String aDestinationName) Creates an output stream to a given destination.String[]Returns the list of destination names to exclude from creating streams that produceTLcdStatusEvents.booleanReturns the blocking hint that is present in theTLcdStatusEvents that are fired to the associatedILcdStatusListeners.voidremoveStatusEventListener(ILcdStatusListener aStatusListener) Removes the givenILcdStatusListenerfrom thisTLcdStatusOutputStreamFactory.voidsetBlockingHint(boolean aBlockingHint) Sets the blocking hint that is present in theTLcdStatusEvents that are fired to the associatedILcdStatusListeners.voidsetExcludedDestinations(String[] aExcludedDestinations) Sets the list of destination names (as given tocreateOutputStream) that must be excluded.
-
Constructor Details
-
TLcdStatusOutputStreamFactory
public TLcdStatusOutputStreamFactory()Creates a newTLcdStatusOutputStreamFactory, ready to use.ILcdStatusListener(s) need to be added to make it useful. -
TLcdStatusOutputStreamFactory
Creates a newTLcdStatusOutputStreamFactorythat delegates the creation of the actualOutputStreamto the givenILcdOutputStreamFactory.- Parameters:
aOutputStreamFactory- The factory to delegate the creation of the actualOutputStreams to.
-
TLcdStatusOutputStreamFactory
Creates a newTLcdStatusOutputStreamFactoryfor the givenILcdOutputStreamFactorythat producesTLcdStatusEvents with the given message.- Parameters:
aOutputStreamFactory- The factory to delegate the creation of the actualOutputStreams to.aMessage- Message to be used in theTLcdStatusEvents. {0} is replaced with the destination name (as provided tocreateOutputStream), {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 forMessageFormat, so for example single quotes need to be escaped by writing them twice. For example, the message:
would result in:"Writing ''{0}'' ... {1}"
The message:"Writing 'someFile.shp' ... 100KB"
would result in:"Writing [{0}] ...""Writing [someFile.shp] ..."
-
TLcdStatusOutputStreamFactory
public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aMessageFormat) Creates a newTLcdStatusOutputStreamFactoryfor the givenILcdOutputStreamFactorythat producesTLcdStatusEvents with messages formatted by the given message format.- Parameters:
aOutputStreamFactory- The factory to delegate the creation of the actualOutputStreams to.aMessageFormat- TheFormatused to create the messages for theTLcdStatusEvents. When formatting, an array of two parameters is given. OneStringthat equals the destination name as provided increateOutputStream, the second parameter is the kilobytes that are already written as aDouble. One could for example create a usable format like this:
or like this:MessageFormat mf = new MessageFormat( "Writing [{0}] ... {1}" ); mf.setFormat( 1, new DecimalFormat( "###,###,###,###KB" ) );new MessageFormat( "Writing [{0}] ..." )
-
TLcdStatusOutputStreamFactory
public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat) Creates a newTLcdStatusOutputStreamFactoryfor the givenILcdOutputStreamFactorythat producesTLcdStatusEvents with messages formatted by the given message formats. All messages are defined identical to that ofTLcdStatusOutputStreamFactory(ILcdOutputStreamFactory, java.text.Format).- Parameters:
aOutputStreamFactory- The factory to delegate the creation of the actualOutputStreams to.aStartBusyMessageFormat- TheFormatused to create the message for theSTART_BUSYTLcdStatusEvent. The message is defined identical as in the other constructor.aProgressMessageFormat- TheFormatused to create the message for thePROGRESSTLcdStatusEvent. The message is defined identical as in the other constructor.aEndBusyMessageFormat- TheFormatused to create the message for theEND_BUSYTLcdStatusEvent. The message is defined identical as in the other constructor.
-
-
Method Details
-
addStatusEventListener
Adds the givenILcdStatusListenerto thisTLcdStatusOutputStreamFactory. As a result, allOutputStreams created afterwards inform this listener about the made progress.- Parameters:
aStatusListener- The listener to add.
-
removeStatusEventListener
Removes the givenILcdStatusListenerfrom thisTLcdStatusOutputStreamFactory.- Parameters:
aStatusListener- The listener to remove.
-
getExcludedDestinations
Returns the list of destination names to exclude from creating streams that produceTLcdStatusEvents.- Returns:
- the list of destination names to exclude from creating streams that produce
TLcdStatusEvents. - See Also:
-
setExcludedDestinations
Sets the list of destination names (as given tocreateOutputStream) that must be excluded. If a destination name is excluded, a regularOutputStreamis created, instead of one that producesTLcdStatusEvents. This can be convenient to for example avoid reporting progress about an accompanying file, such as a.ref(Luciad reference) or a.dbffile (attributes of a shp file).- Parameters:
aExcludedDestinations- The array of regular expressions (case insensitive) that makes up the exclude list. It must not benull. Use for example this array to exclude all destination names that end with.refor with.dbf:
The default is an empty array. Seenew String[]{".*\\.ref", ".*\\.dbf"}java.util.regex.Patternfor a description of regular expressions.
-
isBlockingHint
public boolean isBlockingHint()Returns the blocking hint that is present in the
TLcdStatusEvents that are fired to the associatedILcdStatusListeners.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 associatedILcdStatusListeners.- Parameters:
aBlockingHint- True to suggest blocking, false to suggest non-blocking.- See Also:
-
createOutputStream
Description copied from interface:ILcdOutputStreamFactoryCreates an output stream to a given destination.- Specified by:
createOutputStreamin interfaceILcdOutputStreamFactory- Parameters:
aDestinationName- an accessible destination.- Returns:
- an
OutputStreamto the destination. - Throws:
IOException- when the destination is non accessible.
-