public final class TLcdFailureCachingInputStreamFactory extends Object implements ILcdInputStreamFactory
ILcdInputStreamFactory(the delegate), and remembers for which sources the delegate failed to create an
When asked to
createInputStream(String), it checks whether a previous attempt "recently" failed.
If there is a recent failure, the exception from that previous attempt is thrown.
If there is no such recent failure, the delegate is asked to create an
InputStream for the source.
The amount of time considered "recent" is configured via the constructor arguments.
Recent failures do not affect
canCreateInputStream(String): it always asks the delegate.
ILcdInputStreamFactory is useful when you expect that many input streams will be created
for the same source(s), and it is likely that some of them are not available. As an example, this happens when
lazily decoding a model consisting of many files, and you do not know beforehand which files actually exist.
This class is thread-safe if the delegate is.
|Constructor and Description|
Creates a new instance that decorates the delegate.
|Modifier and Type||Method and Description|
Checks whether this input stream factory can provide access to
public TLcdFailureCachingInputStreamFactory(ILcdInputStreamFactory aDelegate, long aRetryPeriod, TimeUnit aTimeUnit)
The retry period controls how long this input stream factory will wait before attempting to connect to a source that previously failed. If attempts are made before the retry period has passed, the previous exception will be rethrown without trying to connect.
aDelegate- the delegate
aRetryPeriod- the retry period, strictly positive
aTimeUnit- unit of
public boolean canCreateInputStream(String aSource)
aSource. It is acceptable for this method to return
truefor a source while
createInputStreamthrows an exception for that same source.
For performance reasons, we strongly recommend that implementations perform only a simple test.
For example: check the structure of
aSource to see if it is a URI with a specific scheme, but do not verify
aSource really is accessible.
The default implementation of this method returns
Make sure to override this method if you can easily reject sources. This can help avoid pointless invocations of
createInputStream which would have to throw exceptions for unsupported sources.
aSource- the data source to be verified; typically a file name or a URL.
trueif this input stream factory can likely access the source,
public InputStream createInputStream(String aSource) throws IOException
aSource- an accessible data source.
InputStreamfrom the data source.
aSourceis not accepted by
canCreateInputStreamor is not accessible.