public class TLcdStatusInputStreamFactory extends Object implements ILcdInputStreamFactory, ILcdStatusSource
This ILcdInputStreamFactory
creates InputStream
s that report reading progress by
firing TLcdStatusEvent
s to the attached ILcdStatusListener
s. 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 TLcdStatusEvent
s 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).
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.
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 TLcdStatusEvent
s are fired. If the initially
returned size was too small, it will switch to indeterminate progress as soon as this becomes apparent.
Constructor and Description |
---|
TLcdStatusInputStreamFactory()
Creates a new
TLcdStatusInputStreamFactory , ready to use. |
TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Creates a new
TLcdStatusInputStreamFactory that delegates the creation of the actual
InputStream to the given ILcdInputStreamFactory . |
TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory,
Format aMessageFormat)
Creates a new
TLcdStatusInputStreamFactory for the given ILcdInputStreamFactory
that produces TLcdStatusEvent s with messages formatted by the given message format. |
TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory,
Format aStartBusyMessageFormat,
Format aProgressMessageFormat,
Format aEndBusyMessageFormat)
Creates a new
TLcdStatusInputStreamFactory for the given ILcdInputStreamFactory
that produces TLcdStatusEvent s with messages formatted by the given message formats. |
TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory,
String aMessage)
Creates a new
TLcdStatusInputStreamFactory for the given ILcdInputStreamFactory
that produces TLcdStatusEvent s with the given message. |
Modifier and Type | Method and Description |
---|---|
void |
addStatusEventListener(ILcdStatusListener aStatusListener)
Adds the given
ILcdStatusListener to this TLcdStatusInputStreamFactory . |
void |
addStatusListener(ILcdStatusListener aListener)
Registers the given listener so it will receive status events from this source.
|
InputStream |
createInputStream(String aSourceName)
Creates an
InputStream from aSource . |
String[] |
getExcludedSources()
Returns the list of source 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 TLcdStatusInputStreamFactory . |
void |
removeStatusListener(ILcdStatusListener aListener)
Removes the specified listener so it is no longer notified.
|
void |
setBlockingHint(boolean aBlockingHint)
Sets the blocking hint that is present in the
TLcdStatusEvent s that are fired
to the associated ILcdStatusListener s. |
void |
setExcludedSources(String[] aExcludedSources)
Sets the list of source names (as given to
createInputStream ) that must be excluded. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canCreateInputStream
public TLcdStatusInputStreamFactory()
TLcdStatusInputStreamFactory
, ready to use. ILcdStatusListener
(s) need
to be added to make it useful.public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
TLcdStatusInputStreamFactory
that delegates the creation of the actual
InputStream
to the given ILcdInputStreamFactory
.aInputStreamFactory
- The factory to delegate the creation of the actual InputStream
s to.public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, String aMessage)
TLcdStatusInputStreamFactory
for the given ILcdInputStreamFactory
that produces TLcdStatusEvent
s with the given message.aInputStreamFactory
- The factory to delegate the creation of the actual InputStream
s to.aMessage
- Message to be used in the TLcdStatusEvent
s. {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] ..."
public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aMessageFormat)
TLcdStatusInputStreamFactory
for the given ILcdInputStreamFactory
that produces TLcdStatusEvent
s with messages formatted by the given message format.aInputStreamFactory
- The factory to delegate the creation of the actual InputStream
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 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}] ..." )
public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat)
TLcdStatusInputStreamFactory
for the given ILcdInputStreamFactory
that produces TLcdStatusEvent
s with messages formatted by the given message formats.
All messages are defined identical to that of
TLcdStatusInputStreamFactory(ILcdInputStreamFactory, java.text.Format)
.aInputStreamFactory
- The factory to delegate the creation of the actual InputStream
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 TLcdStatusInputStreamFactory
. As a result,
all InputStream
s created afterwards inform this listener about the made progress.aStatusListener
- The listener to add.addStatusListener(com.luciad.util.ILcdStatusListener)
public void removeStatusEventListener(ILcdStatusListener aStatusListener)
ILcdStatusListener
from this TLcdStatusInputStreamFactory
.aStatusListener
- The listener to remove.removeStatusListener(com.luciad.util.ILcdStatusListener)
public void addStatusListener(ILcdStatusListener aListener)
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.
addStatusListener
in interface ILcdStatusSource
aListener
- The listener to be notified when the status has changed.public void removeStatusListener(ILcdStatusListener aListener)
ILcdStatusSource
removeStatusListener
in interface ILcdStatusSource
aListener
- The listener to remove.public String[] getExcludedSources()
TLcdStatusEvent
s.TLcdStatusEvent
s.setExcludedSources(String[])
public void setExcludedSources(String[] aExcludedSources)
createInputStream
) that must be excluded. If a source
name is excluded, a regular InputStream
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).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.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 InputStream createInputStream(String aSourceName) throws IOException
ILcdInputStreamFactory
InputStream
from aSource
.createInputStream
in interface ILcdInputStreamFactory
aSourceName
- an accessible data source.InputStream
from the data source.IOException
- when aSource
is not accepted by canCreateInputStream
or is not accessible.ILcdInputStreamFactory.canCreateInputStream(String)