Class TLcdStatusInputStreamFactory
- All Implemented Interfaces:
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).
This can be also used to not wrap the input stream for specific usages. For example when support for a data format requires random files access, such as TIFF.
This factory excludes the following format(s) by default:
*.tiff?
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.
Limitations
It assumes theInputStream.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.
- Since:
- 8.1
-
Constructor Summary
ConstructorDescriptionCreates a newTLcdStatusInputStreamFactory
, ready to use.TLcdStatusInputStreamFactory
(ILcdInputStreamFactory aInputStreamFactory) Creates a newTLcdStatusInputStreamFactory
that delegates the creation of the actualInputStream
to the givenILcdInputStreamFactory
.TLcdStatusInputStreamFactory
(ILcdInputStreamFactory aInputStreamFactory, String aMessage) Creates a newTLcdStatusInputStreamFactory
for the givenILcdInputStreamFactory
that producesTLcdStatusEvent
s with the given message.TLcdStatusInputStreamFactory
(ILcdInputStreamFactory aInputStreamFactory, Format aMessageFormat) Creates a newTLcdStatusInputStreamFactory
for the givenILcdInputStreamFactory
that producesTLcdStatusEvent
s with messages formatted by the given message format.TLcdStatusInputStreamFactory
(ILcdInputStreamFactory aInputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat) Creates a newTLcdStatusInputStreamFactory
for the givenILcdInputStreamFactory
that producesTLcdStatusEvent
s with messages formatted by the given message formats. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStatusEventListener
(ILcdStatusListener aStatusListener) Adds the givenILcdStatusListener
to thisTLcdStatusInputStreamFactory
.void
addStatusListener
(ILcdStatusListener aListener) Registers the given listener so it will receive status events from this source.createInputStream
(String aSourceName) Creates anInputStream
fromaSource
.String[]
Returns the list of source 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 thisTLcdStatusInputStreamFactory
.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 theTLcdStatusEvent
s that are fired to the associatedILcdStatusListener
s.void
setExcludedSources
(String[] aExcludedSources) Sets the list of source names (as given tocreateInputStream
) that must be excluded.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.io.ILcdInputStreamFactory
canCreateInputStream
-
Constructor Details
-
TLcdStatusInputStreamFactory
public TLcdStatusInputStreamFactory()Creates a newTLcdStatusInputStreamFactory
, ready to use.ILcdStatusListener
(s) need to be added to make it useful. -
TLcdStatusInputStreamFactory
Creates a newTLcdStatusInputStreamFactory
that delegates the creation of the actualInputStream
to the givenILcdInputStreamFactory
.- Parameters:
aInputStreamFactory
- The factory to delegate the creation of the actualInputStream
s to.
-
TLcdStatusInputStreamFactory
Creates a newTLcdStatusInputStreamFactory
for the givenILcdInputStreamFactory
that producesTLcdStatusEvent
s with the given message.- Parameters:
aInputStreamFactory
- The factory to delegate the creation of the actualInputStream
s to.aMessage
- Message to be used in theTLcdStatusEvent
s. {0} is replaced with the source name (as provided tocreateInputStream
), {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 forMessageFormat
, 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] ..."
-
TLcdStatusInputStreamFactory
public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aMessageFormat) Creates a newTLcdStatusInputStreamFactory
for the givenILcdInputStreamFactory
that producesTLcdStatusEvent
s with messages formatted by the given message format.- Parameters:
aInputStreamFactory
- The factory to delegate the creation of the actualInputStream
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 source name as provided increateInputStream
, the second parameter is the percentage of completion as aDouble
in the interval [0,1]. One could for example create a usable format like this:
or like this:MessageFormat mf = new MessageFormat( "Reading [{0}] ... {1} done" ); mf.setFormat( 1, NumberFormat.getPercentInstance() );
new MessageFormat( "Reading [{0}] ..." )
-
TLcdStatusInputStreamFactory
public TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat) Creates a newTLcdStatusInputStreamFactory
for the givenILcdInputStreamFactory
that producesTLcdStatusEvent
s with messages formatted by the given message formats. All messages are defined identical to that ofTLcdStatusInputStreamFactory(ILcdInputStreamFactory, java.text.Format)
.- Parameters:
aInputStreamFactory
- The factory to delegate the creation of the actualInputStream
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 thisTLcdStatusInputStreamFactory
. As a result, allInputStream
s created afterwards inform this listener about the made progress.- Parameters:
aStatusListener
- The listener to add.- See Also:
-
removeStatusEventListener
Removes the givenILcdStatusListener
from thisTLcdStatusInputStreamFactory
.- Parameters:
aStatusListener
- The listener to remove.- See Also:
-
addStatusListener
Description copied from interface: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.- Specified by:
addStatusListener
in interfaceILcdStatusSource
- Parameters:
aListener
- The listener to be notified when the status has changed.
-
removeStatusListener
Description copied from interface:ILcdStatusSource
Removes the specified listener so it is no longer notified.- Specified by:
removeStatusListener
in interfaceILcdStatusSource
- Parameters:
aListener
- The listener to remove.
-
getExcludedSources
Returns the list of source names to exclude from creating streams that produceTLcdStatusEvent
s.- Returns:
- the list of source names to exclude from creating streams that produce
TLcdStatusEvent
s. - See Also:
-
setExcludedSources
Sets the list of source names (as given tocreateInputStream
) that must be excluded. If a source name is excluded, a regularInputStream
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:
aExcludedSources
- 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 source 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:
-
createInputStream
Description copied from interface:ILcdInputStreamFactory
Creates anInputStream
fromaSource
.- Specified by:
createInputStream
in interfaceILcdInputStreamFactory
- Parameters:
aSourceName
- an accessible data source.- Returns:
- an
InputStream
from the data source. - Throws:
IOException
- whenaSource
is not accepted bycanCreateInputStream
or is not accessible.- See Also:
-