|
||||||||||
| 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
A StreamObject is the base object for implementing a Stream. Since Streams provide an asynchronous operation you must provide non-blocking I/O operations for the stream.
To extend this you must:
For Reading - EITHER override the single byte readAByte() OR extend the nonBlockingRead();
For Writing - EITHER override the single byte writeAByte() OR extend the nonBlockingWrite();
For Flushing - override the flushStream() method.
For Closing - override the closeStream() method.
All these methods MUST be non-blocking. They must not call a mThread wait() or sleep() method and they should block the calling thread for as little time as possible. This makes these operations safe to call from native methods.
| Field Summary | |
static int |
napIterations
|
static int |
napTime
|
protected static int |
READWRITE_CLOSED
|
protected static int |
READWRITE_ERROR
|
protected static int |
READWRITE_WOULDBLOCK
|
| Fields inherited from class ewe.io.BasicStreamObject |
closed |
| Fields inherited from class ewe.util.Errorable |
error |
| Constructor Summary | |
StreamObject()
|
|
| Method Summary | |
boolean |
close()
Closes the stream. |
boolean |
closeStream()
This is non-blocking. |
protected int |
doRead(byte[] buf,
int start,
int count,
IOHandle handle,
boolean readCompletely)
This returns: 0 - Stream end reached. |
protected int |
doWrite(byte[] buf,
int start,
int count,
IOHandle handle)
This returns: 0 - Stream closed. |
void |
flush()
Flush all buffered bytes out to the destination. |
boolean |
isOpen()
Returns if the stream is open or not. |
protected void |
nap()
|
protected void |
nap(boolean forReading)
|
int |
nonBlockingRead(byte[] buff,
int start,
int count)
This is the non-blocking read operation. |
int |
nonBlockingWrite(byte[] buff,
int start,
int count)
This is the non-blocking write operation. |
int |
read(byte[] buff,
int offset,
int count)
Reads bytes into a buffer. |
protected int |
readAByte()
This reads one byte of data. |
int |
readBytes(byte[] buf,
int start,
int count)
This returns: 0 - Stream end reached. |
IOHandle |
readBytes(byte[] buf,
int start,
int count,
IOHandle handle,
boolean readCompletely)
This reads bytes from the stream asynchronously. |
void |
write(byte[] buff,
int offset,
int count)
Writes bytes from a buffer to the Stream. |
protected int |
writeAByte(byte val)
This writes one byte of data. |
int |
writeBytes(byte[] buf,
int start,
int count)
This returns: 0 - Stream closed. |
IOHandle |
writeBytes(byte[] buf,
int start,
int count,
IOHandle handle)
This writes bytes to the stream asynchronously. |
| 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 |
flushStream |
| Field Detail |
public static int napIterations
public static int napTime
protected static final int READWRITE_CLOSED
protected static final int READWRITE_ERROR
protected static final int READWRITE_WOULDBLOCK
| Constructor Detail |
public StreamObject()
| Method Detail |
protected void nap(boolean forReading)
protected void nap()
protected int readAByte()
The default implementation simply returns -2 (i.e. read operations are not allowed).
Return values:
protected int writeAByte(byte val)
The default implementation simply returns -2 (i.e. write operations are not allowed).
Return values:
protected int doRead(byte[] buf,
int start,
int count,
IOHandle handle,
boolean readCompletely)
protected int doWrite(byte[] buf,
int start,
int count,
IOHandle handle)
public int readBytes(byte[] buf,
int start,
int count)
buf - Destination byte array to hold incoming data.start - Starting index in buff for incoming data.count - Maximum number of bytes to read.
public int writeBytes(byte[] buf,
int start,
int count)
buf - Source byte array holding data to be written.start - Starting index in buff for data to be written.count - Number of bytes to write.
public IOHandle readBytes(byte[] buf,
int start,
int count,
IOHandle handle,
boolean readCompletely)
buf - Destination byte array to hold incoming data.start - Starting index in buff for incoming data.count - Maximum number of bytes to read.handle - An existing IOHandle for the operation to use and return. If this is null then a
new one will be created and returned.readCompletely - Set this to be true if you require the full number of count bytes
to be read.
public IOHandle writeBytes(byte[] buf,
int start,
int count,
IOHandle handle)
buf - Source byte array holding data to be written.start - Starting index in buff for data to be written.count - Number of bytes to write.handle - An existing IOHandle for the operation to use and return. If this is null then a
new one will be created and returned.
public boolean closeStream()
throws IOException
BasicStream
IOExceptionpublic boolean isOpen()
BasicStream
public int nonBlockingRead(byte[] buff,
int start,
int count)
The default StreamObject implementation of this uses the single byte read() method.
buff - Destination byte array to hold incoming data.start - Starting index in buff for incoming data.count - Maximum number of bytes to read - should never be zero.
public int nonBlockingWrite(byte[] buff,
int start,
int count)
The default StreamObject implementation of this uses the single byte write() method.
buff - Source byte array holding data to be written.start - Starting index in buff for data to be written.count - Number of bytes to write - should never be zero.
public int read(byte[] buff,
int offset,
int count)
throws IOException
Stream
offset - The offset index in the destination array to accept the data.count - The maximum number of bytes to read.
IOException - if an error occurs reading the stream.
public void write(byte[] buff,
int offset,
int count)
throws IOException
Stream
offset - The start index in the array of the data bytes.count - The number of bytes to write.
IOException - if an error occurs writing to the stream.
public void flush()
throws IOException
Stream
IOException - if an error occured.public boolean close()
BasicStream
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||