|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.util.Errorable
ewe.io.BasicStreamObject
ewe.io.StreamObject
ewe.io.RandomStreamObject
ewe.io.RewindableStream
A RewindableStream adapts a BasicStream so that a particular section of the stream (i.e. a set number of bytes, starting from the first byte) can be accessed randomly, while the remaining bytes can only be accessed sequentially.
Such a Stream can be used when you need to decode data from an Input stream, but some pre-processing of some number of starting bytes is needed - for example in image decoding.
As data is read from the stream it is copied into a buffer as well as being returned for consumption. A rewind() operation then causes the stream to seek to the start of the stream, and you can subsequently seek() up to that point.
| Field Summary |
| Fields inherited from class ewe.io.StreamObject |
napIterations, napTime, READWRITE_CLOSED, READWRITE_ERROR, READWRITE_WOULDBLOCK |
| Fields inherited from class ewe.io.BasicStreamObject |
closed |
| Fields inherited from class ewe.util.Errorable |
error |
| Constructor Summary | |
RewindableStream(Stream stream)
|
|
| Method Summary | |
boolean |
canWrite()
Tests if the RandomAccessStream was opened in read-write mode as opposed to read-ony mode. |
boolean |
closeStream()
This is non-blocking. |
boolean |
flushStream()
This is non-blocking. |
boolean |
isOpen()
Returns if the stream is open or not. |
int |
nonBlockingRead(byte[] buffer,
int start,
int length)
This is the non-blocking read operation. |
int |
nonBlockingWrite(byte[] buffer,
int start,
int length)
This is the non-blocking write operation. |
void |
rewind()
|
static void |
rewind(RandomAccessStream stream)
|
boolean |
seekPosition(long pos)
Tell the Stream to move to the specific position. |
long |
tellPosition()
Retrieve the file position. |
static RandomAccessStream |
toRewindableStream(Stream stream)
|
| Methods inherited from class ewe.io.RandomStreamObject |
getFilePosition, getLength, getStreamLength, length, nonBlockingRead, nonBlockingWrite, seek, seek, setLength, setStreamLength, tell, toRandomStream |
| Methods inherited from class ewe.io.StreamObject |
close, doRead, doWrite, flush, nap, nap, read, readAByte, readBytes, readBytes, write, writeAByte, writeBytes, writeBytes |
| Methods inherited from class ewe.io.BasicStreamObject |
getException, getName, read, read, throwIOException, toInputStream, toOutputStream, toStream, write, write |
| Methods inherited from class ewe.util.Errorable |
returnError, returnError, returnError |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Methods inherited from interface ewe.io.BasicStream |
close |
| Methods inherited from interface ewe.io.Stream |
flush, read, read, read, readBytes, readBytes, toInputStream, toOutputStream, write, write, write, writeBytes, writeBytes |
| Constructor Detail |
public RewindableStream(Stream stream)
| Method Detail |
public static RandomAccessStream toRewindableStream(Stream stream)
public static void rewind(RandomAccessStream stream)
throws IOException
IOExceptionpublic boolean canWrite()
BasicRandomAccessStream
public boolean flushStream()
throws IOException
BasicStream
IOException
public boolean closeStream()
throws IOException
BasicStream
closeStream in interface BasicStreamcloseStream in class StreamObjectIOExceptionpublic boolean isOpen()
BasicStream
isOpen in interface BasicStreamisOpen in class StreamObject
public int nonBlockingRead(byte[] buffer,
int start,
int length)
BasicStream
nonBlockingRead in interface BasicStreamnonBlockingRead in class StreamObjectbuffer - Destination byte array to hold incoming data.start - Starting index in buff for incoming data.length - Maximum number of bytes to read - should never be zero.
public int nonBlockingWrite(byte[] buffer,
int start,
int length)
BasicStream
nonBlockingWrite in interface BasicStreamnonBlockingWrite in class StreamObjectbuffer - Source byte array holding data to be written.start - Starting index in buff for data to be written.length - Number of bytes to write - should never be zero.
public boolean seekPosition(long pos)
throws IOException
seekPosition in interface BasicRandomAccessStreamseekPosition in class RandomStreamObjectpos - The position to seek to.
IOException - if an error occured during the seek.
public long tellPosition()
throws IOException
tellPosition in interface BasicRandomAccessStreamtellPosition in class RandomStreamObjectIOException - if an error occured while getting the position.
public void rewind()
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||