|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
java.io.PipedInputStream
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();
| Field Summary |
|---|
| Fields inherited from class java.io.PipedInputStream |
|---|
buffer, in, out, PIPE_SIZE |
| Constructor Summary | |
|---|---|
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. |
|
| 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 |
|---|
afterClose, close, getActiveThreadNames, getResult, read, read, setDefaultPipeSize |
| Methods inherited from class java.io.PipedInputStream |
|---|
available, connect, receive |
| Methods inherited from class java.io.InputStream |
|---|
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)
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.| Method Detail |
|---|
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()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||