Package com.luciad.io

Class ALcdChunkedInputStreamFactory

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

public abstract class ALcdChunkedInputStreamFactory extends Object implements ILcdInputStreamFactory
Factory that creates InputStream instances that can access a data source without requiring a persistent connection to the data or that access happens linearly.

In some environments, e.g. in the cloud, you pay per request and per byte transferred. That is why input streams produced by this factory first try to minimize the number of requests, but switch to minimizing the number of bytes transferred when it appears that the user wants non-linear access.

Determining whether the user wants non-linear access is based on how they use the input stream. Many decoders for tile-based image data exhibit the following access pattern: open an input stream, skip to a known location, read some data, close the stream. An example is the access of Cloud Optimized GeoTIFFs over the internet. When we see "large" skips, we assume that non-linear access is wanted. In that case, rather than actually loading all the skipped bytes, we close the linear input stream and start loading individual chunks. On the internet, this can be done using range-requests. What constitutes a "large" skip, is controlled by the switch limit parameter to the constructor.

Input streams created by this factory are decorators. The initial delegate is a regular InputStream delegate that you instantiate in createLinearInputStream(String). This input stream should be able to read the entire data. When the switch to the chunk-based strategy occurs, the linear delegate is replaced by one that uses an ILcdChunkLoader to load chunks of data. You instantiate the loader in createChunkLoader(String).

Since:
2022.0
  • Constructor Details

    • ALcdChunkedInputStreamFactory

      protected ALcdChunkedInputStreamFactory(int aSwitchLimit, int aChunkSize)
      Creates a new instance.
      Parameters:
      aSwitchLimit - the size limit, in bytes, for a skip to cause the switch from linear access to chunked access
      aChunkSize - the size, in bytes, of a requested chunk
  • Method Details

    • createInputStream

      public InputStream createInputStream(String aSource) throws IOException
      Description copied from interface: ILcdInputStreamFactory
      Creates an InputStream from aSource.
      Specified by:
      createInputStream in interface ILcdInputStreamFactory
      Parameters:
      aSource - an accessible data source.
      Returns:
      an InputStream from the data source.
      Throws:
      IOException - when aSource is not accepted by canCreateInputStream or is not accessible.
      See Also:
    • createLinearInputStream

      protected abstract InputStream createLinearInputStream(String aSource) throws IOException
      Creates the linear input stream that is used initially to access the source. The created input stream should cover the entire data.
      Parameters:
      aSource - an accessible data source
      Returns:
      an input stream for the data source
      Throws:
      IOException - if the data source cannot be accessed
    • createChunkLoader

      protected abstract ILcdChunkLoader createChunkLoader(String aSource) throws IOException
      Creates a chunk loader that is used to access the source incrementally. This method is called when switching from linear to chunked access for the source.
      Parameters:
      aSource - the source for which the linear input stream was initially created
      Returns:
      the loader
      Throws:
      IOException - if the loader cannot be created