Package com.luciad.io

Class TLcdCompositeInputStreamFactory

java.lang.Object
com.luciad.io.TLcdCompositeInputStreamFactory
All Implemented Interfaces:
ILcdInputStreamFactory

public class TLcdCompositeInputStreamFactory extends Object implements ILcdInputStreamFactory
Composite implementation of 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 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 the input stream factory list.
    • TLcdCompositeInputStreamFactory

      public TLcdCompositeInputStreamFactory(Iterable<? extends ILcdInputStreamFactory> aInputStreamFactories)
      Creates a new composite input stream factory that lazily uses the given Iterable to delegate to.
      Parameters:
      aInputStreamFactories - a list of input stream factories
    • TLcdCompositeInputStreamFactory

      public TLcdCompositeInputStreamFactory(ILcdInputStreamFactory... aInputStreamFactories)
      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

      public List<ILcdInputStreamFactory> getInputStreamFactories()
      Returns the list of delegate input stream factories contained in this composite. If the composite does not use an Iterable, delegates can be added or removed by modifying this list.
      Returns:
      the list of delegate input stream factories in this composite
    • canCreateInputStream

      public boolean canCreateInputStream(String aSource)
      Checks whether this input stream factory can provide access to 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.

      Specified by:
      canCreateInputStream in interface ILcdInputStreamFactory
      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

      public InputStream createInputStream(String aSource) throws IOException
      Creates an 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.

      Specified by:
      createInputStream in interface ILcdInputStreamFactory
      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: