Class TLcdCompositeInputStreamFactory
- All Implemented Interfaces:
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.
ILcdInputStreamFactory and TLcdServiceLoader
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.
- Since:
- 2022.0
-
Constructor Summary
ConstructorDescriptionCreates 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 givenIterable
to delegate to. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canCreateInputStream
(String aSource) Checks whether this input stream factory can provide access toaSource
.createInputStream
(String aSource) Creates anInputStream
fromaSource
.Returns the list of delegate input stream factories contained in this composite.
-
Constructor Details
-
TLcdCompositeInputStreamFactory
public TLcdCompositeInputStreamFactory()Creates a new, empty composite input stream factory. This factory will not be able to create input streams until delegate input stream factories are added to theinput stream factory list
. -
TLcdCompositeInputStreamFactory
public TLcdCompositeInputStreamFactory(Iterable<? extends ILcdInputStreamFactory> aInputStreamFactories) Creates a new composite input stream factory that lazily uses the givenIterable
to delegate to.- Parameters:
aInputStreamFactories
- a list of input stream factories
-
TLcdCompositeInputStreamFactory
Creates a new composite input stream factory containing the supplied delegate factories.- Parameters:
aInputStreamFactories
- delegate factories to be added to the composite
-
-
Method Details
-
getInputStreamFactories
Returns the list of delegate input stream factories contained in this composite. If the composite does not use anIterable
, delegates can be added or removed by modifying this list.- Returns:
- the list of delegate input stream factories in this composite
-
canCreateInputStream
Checks whether this input stream factory can provide access toaSource
. It is acceptable for this method to returntrue
for a source whilecreateInputStream
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 thataSource
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 ofcreateInputStream
which would have to throw exceptions for unsupported sources.The implementation in
TLcdCompositeInputStreamFactory
returnstrue
if any of the input stream factories it has available does so.- Specified by:
canCreateInputStream
in interfaceILcdInputStreamFactory
- Parameters:
aSource
- the data source to be verified; typically a file name or a URL.- Returns:
true
if this input stream factory can likely access the source,false
otherwise.- See Also:
-
createInputStream
Creates anInputStream
fromaSource
.The implementation in
TLcdCompositeInputStreamFactory
delegates to the first input stream factory whosecreateInputStream()
method does not throw an exception. Only input stream factories that claim theycanCreateInputStream(java.lang.String)
for the source are used.- Specified by:
createInputStream
in interfaceILcdInputStreamFactory
- Parameters:
aSource
- the source for which an input stream should be created- Returns:
- an input stream created by the selected delegate factory
- Throws:
IOException
- if no delegate was able to create an input stream- See Also:
-