public class TLcdStatusOutputStreamFactory extends Object implements 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.
Constructor and Description |
---|
TLcdStatusOutputStreamFactory()
Creates a new
TLcdStatusOutputStreamFactory , ready to use. |
TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
Creates a new
TLcdStatusOutputStreamFactory that delegates the creation of the actual
OutputStream to the given ILcdOutputStreamFactory . |
TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory,
Format aMessageFormat)
Creates a new
TLcdStatusOutputStreamFactory for the given ILcdOutputStreamFactory
that produces TLcdStatusEvent s with messages formatted by the given message format. |
TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory,
Format aStartBusyMessageFormat,
Format aProgressMessageFormat,
Format aEndBusyMessageFormat)
Creates a new
TLcdStatusOutputStreamFactory for the given ILcdOutputStreamFactory
that produces TLcdStatusEvent s with messages formatted by the given message formats. |
TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory,
String aMessage)
Creates a new
TLcdStatusOutputStreamFactory for the given ILcdOutputStreamFactory
that produces TLcdStatusEvent s with the given message. |
Modifier and Type | Method and Description |
---|---|
void |
addStatusEventListener(ILcdStatusListener aStatusListener)
Adds the given
ILcdStatusListener to this TLcdStatusOutputStreamFactory . |
OutputStream |
createOutputStream(String aDestinationName)
Creates an output stream to a given destination.
|
String[] |
getExcludedDestinations()
Returns the list of destination names to exclude from creating streams that produce
TLcdStatusEvent s. |
boolean |
isBlockingHint()
Returns the blocking hint that is present in the
TLcdStatusEvent s that are
fired to the associated ILcdStatusListener s. |
void |
removeStatusEventListener(ILcdStatusListener aStatusListener)
Removes the given
ILcdStatusListener from this TLcdStatusOutputStreamFactory . |
void |
setBlockingHint(boolean aBlockingHint)
Sets the blocking hint that is present in the
TLcdStatusEvent s that are fired
to the associated ILcdStatusListener s. |
void |
setExcludedDestinations(String[] aExcludedDestinations)
Sets the list of destination names (as given to
createOutputStream ) that must be excluded. |
public TLcdStatusOutputStreamFactory()
TLcdStatusOutputStreamFactory
, ready to use. ILcdStatusListener
(s) need
to be added to make it useful.public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
TLcdStatusOutputStreamFactory
that delegates the creation of the actual
OutputStream
to the given ILcdOutputStreamFactory
.aOutputStreamFactory
- The factory to delegate the creation of the actual OutputStream
s to.public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, String aMessage)
TLcdStatusOutputStreamFactory
for the given ILcdOutputStreamFactory
that produces TLcdStatusEvent
s with the given message.aOutputStreamFactory
- The factory to delegate the creation of the actual OutputStream
s to.aMessage
- Message to be used in the TLcdStatusEvent
s. {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] ..."
public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aMessageFormat)
TLcdStatusOutputStreamFactory
for the given ILcdOutputStreamFactory
that produces TLcdStatusEvent
s with messages formatted by the given message format.aOutputStreamFactory
- The factory to delegate the creation of the actual OutputStream
s to.aMessageFormat
- The Format
used to create the messages for the TLcdStatusEvent
s.
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}] ..." )
public TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat)
TLcdStatusOutputStreamFactory
for the given ILcdOutputStreamFactory
that produces TLcdStatusEvent
s with messages formatted by the given message formats.
All messages are defined identical to that of
TLcdStatusOutputStreamFactory(ILcdOutputStreamFactory, java.text.Format)
.aOutputStreamFactory
- The factory to delegate the creation of the actual OutputStream
s 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.public void addStatusEventListener(ILcdStatusListener aStatusListener)
ILcdStatusListener
to this TLcdStatusOutputStreamFactory
. As a result,
all OutputStream
s created afterwards inform this listener about the made progress.aStatusListener
- The listener to add.public void removeStatusEventListener(ILcdStatusListener aStatusListener)
ILcdStatusListener
from this TLcdStatusOutputStreamFactory
.aStatusListener
- The listener to remove.public String[] getExcludedDestinations()
TLcdStatusEvent
s.TLcdStatusEvent
s.setExcludedDestinations(String[])
public void setExcludedDestinations(String[] aExcludedDestinations)
createOutputStream
) that must be excluded. If a
destination name is excluded, a regular OutputStream
is created, instead of one that produces
TLcdStatusEvent
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).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.public boolean isBlockingHint()
Returns the blocking hint that is present in the TLcdStatusEvent
s that are
fired to the associated ILcdStatusListener
s.
Default is true.
setBlockingHint(boolean)
,
TLcdStatusEvent.isBlockingHint()
public void setBlockingHint(boolean aBlockingHint)
Sets the blocking hint that is present in the TLcdStatusEvent
s that are fired
to the associated ILcdStatusListener
s.
aBlockingHint
- True to suggest blocking, false to suggest non-blocking.isBlockingHint()
,
TLcdStatusEvent.setBlockingHint(boolean)
public OutputStream createOutputStream(String aDestinationName) throws IOException
ILcdOutputStreamFactory
createOutputStream
in interface ILcdOutputStreamFactory
aDestinationName
- an accessible destination.OutputStream
to the destination.IOException
- when the destination is non accessible.