|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
com.gc.iotools.stream.is.InputStreamFromOutputStream<Void>
com.gc.iotools.stream.is.ReadAheadInputStream
public class ReadAheadInputStream
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();
| Constructor Summary | |
|---|---|
ReadAheadInputStream(InputStream source)
|
|
ReadAheadInputStream(InputStream source,
int bufferSize)
|
|
ReadAheadInputStream(InputStream source,
int bufferSize,
ExecutionModel executionModel)
|
|
ReadAheadInputStream(InputStream source,
int bufferSize,
ExecutorService executorService)
|
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class com.gc.iotools.stream.is.InputStreamFromOutputStream |
|---|
close, getActiveThreadNames, getResult, read, read, setDefaultBufferSize, setDefaultPipeSize |
| Methods inherited from class java.io.InputStream |
|---|
available, mark, markSupported, read, reset, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ReadAheadInputStream(InputStream source)
public ReadAheadInputStream(InputStream source,
int bufferSize)
public ReadAheadInputStream(InputStream source,
int bufferSize,
ExecutionModel executionModel)
public ReadAheadInputStream(InputStream source,
int bufferSize,
ExecutorService executorService)
| Method Detail |
|---|
protected Void produce(OutputStream sink)
throws Exception
InputStreamFromOutputStream
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()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||