public abstract class ALcdChunkedInputStreamFactory extends Object implements ILcdInputStreamFactory
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)
.
Modifier | Constructor and Description |
---|---|
protected |
ALcdChunkedInputStreamFactory(int aSwitchLimit,
int aChunkSize)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected abstract ILcdChunkLoader |
createChunkLoader(String aSource)
Creates a chunk loader that is used to access the source incrementally.
|
InputStream |
createInputStream(String aSource)
Creates an
InputStream from aSource . |
protected abstract InputStream |
createLinearInputStream(String aSource)
Creates the linear input stream that is used initially to access the source.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canCreateInputStream
protected ALcdChunkedInputStreamFactory(int aSwitchLimit, int aChunkSize)
aSwitchLimit
- the size limit, in bytes, for a skip to cause the switch from linear access to chunked accessaChunkSize
- the size, in bytes, of a requested chunkpublic InputStream createInputStream(String aSource) throws IOException
ILcdInputStreamFactory
InputStream
from aSource
.createInputStream
in interface ILcdInputStreamFactory
aSource
- an accessible data source.InputStream
from the data source.IOException
- when aSource
is not accepted by canCreateInputStream
or is not accessible.ILcdInputStreamFactory.canCreateInputStream(String)
protected abstract InputStream createLinearInputStream(String aSource) throws IOException
aSource
- an accessible data sourceIOException
- if the data source cannot be accessedprotected abstract ILcdChunkLoader createChunkLoader(String aSource) throws IOException
aSource
- the source for which the linear input stream was initially createdIOException
- if the loader cannot be created