com.gc.iotools.stream.is
public class ReadAheadInputStream extends InputStreamFromOutputStream<Void>
This class tries to read the InputStream passed as a parameter
in a memory buffer, thus improving the reading performances.
This can speed up reading when the time spent in reading from the stream is same order as the time spent in elaborating the stream, because it decouples the reading process and the elaboration in two different threads putting them in parallel.
Sample Usage:
InputStream source = ... some slow InputStream. InputStream fastIs = new ReadAheadInputStream(source); //use here fastIs instead of the source InputStream ... fastIs.close();
buffer, in, out, PIPE_SIZE| Constructor and Description |
|---|
ReadAheadInputStream(InputStream source)
Constructor for ReadAheadInputStream.
|
ReadAheadInputStream(InputStream source,
int bufferSize)
Constructor for ReadAheadInputStream.
|
ReadAheadInputStream(InputStream source,
int bufferSize,
ExecutionModel executionModel)
Constructor for ReadAheadInputStream.
|
ReadAheadInputStream(InputStream source,
int bufferSize,
ExecutorService executorService)
Constructor for ReadAheadInputStream.
|
| Modifier and Type | Method and Description |
|---|---|
protected Void |
produce(OutputStream sink)
This method must be implemented by the user of this class to produce the
data that must be read from the external
InputStream. |
afterClose, close, getActiveThreadNames, getResult, read, read, read, setDefaultPipeSizeavailable, connect, receivemark, markSupported, reset, skippublic ReadAheadInputStream(InputStream source)
Constructor for ReadAheadInputStream.
source - a InputStream object.public ReadAheadInputStream(InputStream source, int bufferSize)
Constructor for ReadAheadInputStream.
source - a InputStream object.bufferSize - a int.public ReadAheadInputStream(InputStream source, int bufferSize, ExecutionModel executionModel)
Constructor for ReadAheadInputStream.
source - a InputStream object.bufferSize - a int.executionModel - a ExecutionModel object.public ReadAheadInputStream(InputStream source, int bufferSize, ExecutorService executorService)
Constructor for ReadAheadInputStream.
source - a InputStream object.bufferSize - a int.executorService - a ExecutorService object.protected Void produce(OutputStream sink) throws Exception
This method must be implemented by the user of this class to produce the
data that must be read from the external InputStream.
Special care must be paid passing arguments to this method or setting global fields because it is executed in another thread.
The right way to set a field variable is to return a value in the
produceand retrieve it in the getResult().
produce in class InputStreamFromOutputStream<Void>sink - the implementing class should write its data to this stream.Exception - the exception eventually thrown by the implementing class is
returned by the InputStreamFromOutputStream.read() methods.InputStreamFromOutputStream.getResult()Copyright © 2008–2015. All rights reserved.