Class TLcdStatusInputStreamFactory
- All Implemented Interfaces:
ILcdInputStreamFactory,ILcdStatusSource
This ILcdInputStreamFactory creates InputStreams that report reading progress by
firing TLcdStatusEvents to the attached ILcdStatusListeners. 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 TLcdStatusEvents 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 TLcdStatusEvents 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
ConstructorsConstructorDescriptionCreates a newTLcdStatusInputStreamFactory, ready to use.TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory) Creates a newTLcdStatusInputStreamFactorythat delegates the creation of the actualInputStreamto the givenILcdInputStreamFactory.TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, String aMessage) Creates a newTLcdStatusInputStreamFactoryfor the givenILcdInputStreamFactorythat producesTLcdStatusEvents with the given message.TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aMessageFormat) Creates a newTLcdStatusInputStreamFactoryfor the givenILcdInputStreamFactorythat producesTLcdStatusEvents with messages formatted by the given message format.TLcdStatusInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory, Format aStartBusyMessageFormat, Format aProgressMessageFormat, Format aEndBusyMessageFormat) Creates a newTLcdStatusInputStreamFactoryfor the givenILcdInputStreamFactorythat producesTLcdStatusEvents with messages formatted by the given message formats. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStatusEventListener(ILcdStatusListener aStatusListener) Adds the givenILcdStatusListenerto thisTLcdStatusInputStreamFactory.voidaddStatusListener(ILcdStatusListener aListener) Registers the given listener so it will receive status events from this source.createInputStream(String aSourceName) Creates anInputStreamfromaSource.String[]Returns the list of source 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 thisTLcdStatusInputStreamFactory.voidremoveStatusListener(ILcdStatusListener aListener) Removes the specified listener so it is no longer notified.voidsetBlockingHint(boolean aBlockingHint) Sets the blocking hint that is present in theTLcdStatusEvents that are fired to the associatedILcdStatusListeners.voidsetExcludedSources(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, waitMethods 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 newTLcdStatusInputStreamFactorythat delegates the creation of the actualInputStreamto the givenILcdInputStreamFactory.- Parameters:
aInputStreamFactory- The factory to delegate the creation of the actualInputStreams to.
-
TLcdStatusInputStreamFactory
Creates a newTLcdStatusInputStreamFactoryfor the givenILcdInputStreamFactorythat producesTLcdStatusEvents with the given message.- Parameters:
aInputStreamFactory- The factory to delegate the creation of the actualInputStreams to.aMessage- Message to be used in theTLcdStatusEvents. {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 newTLcdStatusInputStreamFactoryfor the givenILcdInputStreamFactorythat producesTLcdStatusEvents with messages formatted by the given message format.- Parameters:
aInputStreamFactory- The factory to delegate the creation of the actualInputStreams to.aMessageFormat- TheFormatused to create the messages for theTLcdStatusEvents. When formatting, an array of two parameters is given. OneStringthat equals the source name as provided increateInputStream, the second parameter is the percentage of completion as aDoublein 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 newTLcdStatusInputStreamFactoryfor the givenILcdInputStreamFactorythat producesTLcdStatusEvents 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 actualInputStreams 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 thisTLcdStatusInputStreamFactory. As a result, allInputStreams created afterwards inform this listener about the made progress.- Parameters:
aStatusListener- The listener to add.- See Also:
-
removeStatusEventListener
Removes the givenILcdStatusListenerfrom thisTLcdStatusInputStreamFactory.- Parameters:
aStatusListener- The listener to remove.- See Also:
-
addStatusListener
Description copied from interface:ILcdStatusSourceRegisters 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
ALcdWeakStatusListenerinstance as status listener.- Specified by:
addStatusListenerin interfaceILcdStatusSource- Parameters:
aListener- The listener to be notified when the status has changed.
-
removeStatusListener
Description copied from interface:ILcdStatusSourceRemoves the specified listener so it is no longer notified.- Specified by:
removeStatusListenerin interfaceILcdStatusSource- Parameters:
aListener- The listener to remove.
-
getExcludedSources
Returns the list of source names to exclude from creating streams that produceTLcdStatusEvents.- Returns:
- the list of source names to exclude from creating streams that produce
TLcdStatusEvents. - See Also:
-
setExcludedSources
Sets the list of source names (as given tocreateInputStream) that must be excluded. If a source name is excluded, a regularInputStreamis 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:
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.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:
-
createInputStream
Description copied from interface:ILcdInputStreamFactoryCreates anInputStreamfromaSource.- Specified by:
createInputStreamin interfaceILcdInputStreamFactory- Parameters:
aSourceName- an accessible data source.- Returns:
- an
InputStreamfrom the data source. - Throws:
IOException- whenaSourceis not accepted bycanCreateInputStreamor is not accessible.- See Also:
-