Class TLcdStatusOutputStreamFactory
- All Implemented Interfaces:
ILcdOutputStreamFactory
This ILcdOutputStreamFactory
creates OutputStream
s that report writing progress by
firing TLcdStatusEvent
s to the attached ILcdStatusListener
s. 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 TLcdStatusEvent
s 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
ConstructorDescriptionCreates a newTLcdStatusOutputStreamFactory
, ready to use.TLcdStatusOutputStreamFactory
(ILcdOutputStreamFactory aOutputStreamFactory) Creates a newTLcdStatusOutputStreamFactory
that delegates the creation of the actualOutputStream
to the givenILcdOutputStreamFactory
.TLcdStatusOutputStreamFactory
(ILcdOutputStreamFactory aOutputStreamFactory, String aMessage) Creates a newTLcdStatusOutputStreamFactory
for the givenILcdOutputStreamFactory
that producesTLcdStatusEvent
s with the given message.TLcdStatusOutputStreamFactory
(ILcdOutputStreamFactory aOutputStreamFactory, Format aMessageFormat) Creates a newTLcdStatusOutputStreamFactory
for the givenILcdOutputStreamFactory
that producesTLcdStatusEvent
s with messages formatted by the given message format.TLcdStatusOutputStreamFactory
(ILcdOutputStreamFactory aOutputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat) Creates a newTLcdStatusOutputStreamFactory
for the givenILcdOutputStreamFactory
that producesTLcdStatusEvent
s with messages formatted by the given message formats. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStatusEventListener
(ILcdStatusListener aStatusListener) Adds the givenILcdStatusListener
to 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 produceTLcdStatusEvent
s.boolean
Returns the blocking hint that is present in theTLcdStatusEvent
s that are fired to the associatedILcdStatusListener
s.void
removeStatusEventListener
(ILcdStatusListener aStatusListener) Removes the givenILcdStatusListener
from thisTLcdStatusOutputStreamFactory
.void
setBlockingHint
(boolean aBlockingHint) Sets the blocking hint that is present in theTLcdStatusEvent
s that are fired to the associatedILcdStatusListener
s.void
setExcludedDestinations
(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 newTLcdStatusOutputStreamFactory
that delegates the creation of the actualOutputStream
to the givenILcdOutputStreamFactory
.- Parameters:
aOutputStreamFactory
- The factory to delegate the creation of the actualOutputStream
s to.
-
TLcdStatusOutputStreamFactory
Creates a newTLcdStatusOutputStreamFactory
for the givenILcdOutputStreamFactory
that producesTLcdStatusEvent
s with the given message.- Parameters:
aOutputStreamFactory
- The factory to delegate the creation of the actualOutputStream
s to.aMessage
- Message to be used in theTLcdStatusEvent
s. {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 newTLcdStatusOutputStreamFactory
for the givenILcdOutputStreamFactory
that producesTLcdStatusEvent
s with messages formatted by the given message format.- Parameters:
aOutputStreamFactory
- The factory to delegate the creation of the actualOutputStream
s to.aMessageFormat
- TheFormat
used to create the messages for theTLcdStatusEvent
s. When formatting, an array of two parameters is given. OneString
that 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 newTLcdStatusOutputStreamFactory
for the givenILcdOutputStreamFactory
that producesTLcdStatusEvent
s 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 actualOutputStream
s to.aStartBusyMessageFormat
- TheFormat
used to create the message for theSTART_BUSY
TLcdStatusEvent
. The message is defined identical as in the other constructor.aProgressMessageFormat
- TheFormat
used to create the message for thePROGRESS
TLcdStatusEvent
. The message is defined identical as in the other constructor.aEndBusyMessageFormat
- TheFormat
used to create the message for theEND_BUSY
TLcdStatusEvent
. The message is defined identical as in the other constructor.
-
-
Method Details
-
addStatusEventListener
Adds the givenILcdStatusListener
to thisTLcdStatusOutputStreamFactory
. As a result, allOutputStream
s created afterwards inform this listener about the made progress.- Parameters:
aStatusListener
- The listener to add.
-
removeStatusEventListener
Removes the givenILcdStatusListener
from thisTLcdStatusOutputStreamFactory
.- Parameters:
aStatusListener
- The listener to remove.
-
getExcludedDestinations
Returns the list of destination names to exclude from creating streams that produceTLcdStatusEvent
s.- Returns:
- the list of destination names to exclude from creating streams that produce
TLcdStatusEvent
s. - See Also:
-
setExcludedDestinations
Sets the list of destination names (as given tocreateOutputStream
) that must be excluded. If a destination name is excluded, a regularOutputStream
is created, instead of one that producesTLcdStatusEvent
s. 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 benull
. Use for example this array to exclude all destination names that end with.ref
or with.dbf
:
The default is an empty array. Seenew String[]{".*\\.ref", ".*\\.dbf"}
java.util.regex.Pattern
for a description of regular expressions.
-
isBlockingHint
public boolean isBlockingHint()Returns the blocking hint that is present in the
TLcdStatusEvent
s that are fired to the associatedILcdStatusListener
s.Default is true.
- Returns:
- the blocking hint.
- See Also:
-
setBlockingHint
public void setBlockingHint(boolean aBlockingHint) Sets the blocking hint that is present in the
TLcdStatusEvent
s that are fired to the associatedILcdStatusListener
s.- Parameters:
aBlockingHint
- True to suggest blocking, false to suggest non-blocking.- See Also:
-
createOutputStream
Description copied from interface:ILcdOutputStreamFactory
Creates an output stream to a given destination.- Specified by:
createOutputStream
in interfaceILcdOutputStreamFactory
- Parameters:
aDestinationName
- an accessible destination.- Returns:
- an
OutputStream
to the destination. - Throws:
IOException
- when the destination is non accessible.
-