public class TLcdCompositeInputStreamFactory extends Object implements ILcdInputStreamFactory
ILcdInputStreamFactory
.
Any number of input stream factories can be added to this composite.
The createInputStream(String)
method will delegate to the first factory in the list that
does not throw or return null
for the given source.
You can create a factory with good default behavior like so:
ILcdInputStreamFactory inputStreamFactory =
new TLcdCompositeInputStreamFactory(TLcdServiceLoader.getInstance(ILcdInputStreamFactory.class));
Using TLcdServiceLoader
, it combines all input stream factories of all available optional components.
It can therefore provide sensible default behavior for almost all data formats.
If you need to support a different storage mechanism, you can implement your own input stream factories.
By annotating them with LcdService
and generate the services files using the
annotation processor, your factories take precedence when using the default priority (or more important).
For more information, refer to the
Working with the services mechanism article.
Constructor and Description |
---|
TLcdCompositeInputStreamFactory()
Creates a new, empty composite input stream factory.
|
TLcdCompositeInputStreamFactory(ILcdInputStreamFactory... aInputStreamFactories)
Creates a new composite input stream factory containing the supplied delegate factories.
|
TLcdCompositeInputStreamFactory(Iterable<? extends ILcdInputStreamFactory> aInputStreamFactories)
Creates a new composite input stream factory that lazily uses the given
Iterable to delegate to. |
Modifier and Type | Method and Description |
---|---|
boolean |
canCreateInputStream(String aSource)
Checks whether this input stream factory can provide access to
aSource . |
InputStream |
createInputStream(String aSource)
Creates an
InputStream from aSource . |
List<ILcdInputStreamFactory> |
getInputStreamFactories()
Returns the list of delegate input stream factories contained in this composite.
|
public TLcdCompositeInputStreamFactory()
input stream factory list
.public TLcdCompositeInputStreamFactory(Iterable<? extends ILcdInputStreamFactory> aInputStreamFactories)
Iterable
to delegate to.aInputStreamFactories
- a list of input stream factoriespublic TLcdCompositeInputStreamFactory(ILcdInputStreamFactory... aInputStreamFactories)
aInputStreamFactories
- delegate factories to be added to the compositepublic List<ILcdInputStreamFactory> getInputStreamFactories()
Iterable
, delegates can be added or removed by modifying this list.public boolean canCreateInputStream(String aSource)
aSource
. It is acceptable for this method to
return true
for a source while createInputStream
throws 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
that aSource
really is accessible.
The default implementation of this method returns true
.
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.
The implementation in TLcdCompositeInputStreamFactory
returns true
if any of the
input stream factories it has available does so.
canCreateInputStream
in interface ILcdInputStreamFactory
aSource
- the data source to be verified; typically a file name or a URL.true
if this input stream factory can likely access the source, false
otherwise.ILcdInputStreamFactory.createInputStream(String)
public InputStream createInputStream(String aSource) throws IOException
InputStream
from aSource
.
The implementation in TLcdCompositeInputStreamFactory
delegates to the first input stream factory
whose createInputStream()
method does not throw an exception.
Only input stream factories that claim they canCreateInputStream(java.lang.String)
for the source are used.
createInputStream
in interface ILcdInputStreamFactory
aSource
- the source for which an input stream should be createdIOException
- if no delegate was able to create an input streamILcdInputStreamFactory.canCreateInputStream(String)