|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream java.io.FilterInputStream mediautil.gen.directio.SplitInputStream
public class SplitInputStream
This class enables the Sharing of an InputStream (Say from a file) by One or more IterativeReaders with a main reader. The main reader is any reader like say an ImageReader for reading images.
This is accomplished by using a common buffer. The read/skip calls on this class by the main reader calls nextRead() on the SubStreams to consume the buffered data before the buffer is filled again.
IterativeReader
Constructor Summary | |
---|---|
SplitInputStream(InputStream mainStream)
Creates a new SplitInputStream Object with default parameters. |
|
SplitInputStream(InputStream mainStream,
int bufSize,
int incSize)
Creates a new SplitInputStream Object. |
Method Summary | |
---|---|
int |
attachSubReader(IterativeReader code,
InputStream subStream)
This call must follow a createSubStream() call to attach an IterativeReader to read from the subStream created. |
int |
available()
Available method of the SplitInputStream. |
InputStream |
createSubStream()
Creates a Sub Stream for use by an instance of IterativeReader. |
InputStream |
createSubStream(int minReadSize,
int readCushion)
Creates a Sub Stream for use by an instance of IterativeReader. |
void |
detachSubReader(int subReaderId)
Detaches a Sub Reader and its Stream. |
int |
getMaxBufSize()
Returns the max bufSize. |
int |
read()
Read method of the SplitInputStream. |
int |
read(byte[] b,
int off,
int len)
Read method of the SplitInputStream. |
long |
skip(long n)
Skip method of the SplitInputStream. |
void |
wrapup()
This should be called when the Main Object (Say ImageReader) has finished reading. |
Methods inherited from class java.io.FilterInputStream |
---|
close, mark, markSupported, read, reset |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SplitInputStream(InputStream mainStream, int bufSize, int incSize)
mainStream
- The main input Stream, say a FileInputStream. Note that
this need not be buffered since SplitInputStream itself does buffering.
The Main Object (Say ImageReader) will read from the newly constructed
SplitInputStream object after attaching zero or more IterativeReaders.
The SplitInputStream and Sub Streams see the same data as in mainStream.bufSize
- The Initial BufferSize. This will be increased if one of
the Sub Readers read way beyond the requested SizeincSize
- The buffer Size is always increase/decreased in multiples
of incSizepublic SplitInputStream(InputStream mainStream)
mainStream
- The main input Stream, say a FileInputStream. Note that
this need not be buffered since SplitInputStream itself does buffering.
The Main Object (Say ImageReader) will read from the newly constructed
SplitInputStream object after attaching zero or more IterativeReaders.
The SplitInputStream and Sub Streams see the same data as in mainStream.Method Detail |
---|
public InputStream createSubStream(int minReadSize, int readCushion)
minReadSize
- The minimum Number of Bytes that should be passed to
the nextRead method of the IterativeReader. This value is limited to
atleast 512.readCushion
- The maximum number of bytes by which a nextRead() call
to the subReader may overshoot the requested number of bytes. If a
nextRead() call exceeds the limit beyond readCushion a buffer expansion
may result which affects performance. This value is limited to atleast
512.
Please note that the returned Input Stream does not strictly confirm to jdk's InputStream spec in the following:
IterativeReader
,
attachSubReader(IterativeReader, InputStream)
,
ByteCounter
public InputStream createSubStream()
Please note that the returned Input Stream does not strictly confirm to jdk's InputStream spec in the following:
IterativeReader
,
attachSubReader(IterativeReader,InputStream)
,
ByteCounter
public int attachSubReader(IterativeReader code, InputStream subStream)
code
- The IterativeReader to share the main Input. The nextRead()
method is called on code by the read/skip calls on SplitInputStream as
and when required.subStream
- The SubStream which was created using createSubStream()
call and not yet attached. The nextRead() calls to the IterativeReader
specified by the parameter code must read from this subStream.
IterativeReader.nextRead(int)
,
createSubStream(int,int)
,
detachSubReader(int)
public void detachSubReader(int subReaderId)
subReaderId
- Id to detachattachSubReader(IterativeReader,InputStream)
public int read(byte[] b, int off, int len) throws IOException
read
in class FilterInputStream
IOException
- If the underlying stream throws an IOException or
if the nextRead() call of a subReader throws an IOExceptionpublic int read() throws IOException
read
in class FilterInputStream
IOException
- If the underlying stream throws an IOException or
if the nextRead() call of a subReader throws an IOExceptionpublic long skip(long n) throws IOException
skip
in class FilterInputStream
IOException
- If the underlying stream throws an IOException or
if the nextRead() call of a subReader throws an IOExceptionpublic int available()
available
in class FilterInputStream
public int getMaxBufSize()
public void wrapup() throws IOException
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |