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
nullfor the given source.
You can create a factory with good default behavior like so:
ILcdInputStreamFactory inputStreamFactory = new TLcdCompositeInputStreamFactory(TLcdServiceLoader.getInstance(ILcdInputStreamFactory.class));
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|
Creates a new, empty composite input stream factory.
Creates a new composite input stream factory containing the supplied delegate factories.
Creates a new composite input stream factory that lazily uses the given
|Modifier and Type||Method and Description|
Checks whether this input stream factory can provide access to
Returns the list of delegate input stream factories contained in this composite.
input stream factory list.
public TLcdCompositeInputStreamFactory(Iterable<? extends ILcdInputStreamFactory> aInputStreamFactories)
Iterableto delegate to.
aInputStreamFactories- a list of input stream factories
public TLcdCompositeInputStreamFactory(ILcdInputStreamFactory... aInputStreamFactories)
aInputStreamFactories- delegate factories to be added to the composite
public 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
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.
The implementation in
true if any of the
input stream factories it has available does so.
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
The implementation in
TLcdCompositeInputStreamFactory delegates to the first input stream factory
createInputStream() method does not throw an exception.
Only input stream factories that claim they
canCreateInputStream(java.lang.String) for the source are used.
aSource- the source for which an input stream should be created
IOException- if no delegate was able to create an input stream