ewe.io
Class BasicStreamObject

java.lang.Object
  extended byewe.util.Errorable
      extended byewe.io.BasicStreamObject
All Implemented Interfaces:
BasicStream, Stream, Streamable
Direct Known Subclasses:
BlockingStreamObject, StreamObject

public abstract class BasicStreamObject
extends Errorable
implements Stream, Streamable


Field Summary
protected  boolean closed
           
 
Fields inherited from class ewe.util.Errorable
error
 
Constructor Summary
BasicStreamObject()
           
 
Method Summary
 IOException getException(String defaultText)
           
 String getName()
          Get the name associated with this Streamable object.
 int read()
          Read in a single byte from the stream.
 int read(byte[] buff)
          Read bytes into a buffer.
 void throwIOException(String defaultText)
           
 InputStream toInputStream()
           
 OutputStream toOutputStream()
           
 Handle toStream(boolean randomString, String mode)
          Requests the possibly asynchronous creation of a Stream object for reading or writing.
 void write(byte[] buff)
          Writes bytes from a buffer to the Stream.
 void write(int value)
          Write out a single byte to the stream.
 
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.Stream
flush, read, readBytes, readBytes, write, writeBytes, writeBytes
 
Methods inherited from interface ewe.io.BasicStream
close, closeStream, flushStream, isOpen, nonBlockingRead, nonBlockingWrite
 

Field Detail

closed

protected boolean closed
Constructor Detail

BasicStreamObject

public BasicStreamObject()
Method Detail

toStream

public Handle toStream(boolean randomString,
                       String mode)
Description copied from interface: Streamable
Requests the possibly asynchronous creation of a Stream object for reading or writing.

Specified by:
toStream in interface Streamable
Parameters:
randomString - if this is true then a request is being made for a RandomAccessStream, otherwise either a readable or writable Stream will be returned.
mode - For RandomAccessStreams this can be "r" or "rw". For writable Streams this should be "w" or "a" (for append) and for readable Streams it should be "r".
Returns:
A Handle used to form monitoring the creation process and for retrieving the final value.

The calling code should wait on the Handle.Success flag to be set. If this happens the returnValue of the Handle will be set to the acquired Stream. If the Handle fails then the errorObject of the Handle will be set to an IOException.


getName

public String getName()
Description copied from interface: Streamable
Get the name associated with this Streamable object.

Specified by:
getName in interface Streamable

read

public int read(byte[] buff)
         throws IOException
Description copied from interface: Stream
Read bytes into a buffer. Reads up to buff.length bytes starting at index 0. This method blocks the current Coroutine, but allows others to continue executing.

Specified by:
read in interface Stream
Returns:
The number of bytes actually read, or -1 if the stream has ended.
Throws:
IOException - if an error occurs reading the stream.

write

public void write(byte[] buff)
           throws IOException
Description copied from interface: Stream
Writes bytes from a buffer to the Stream. This method blocks the current Coroutine until all bytes in the array are written, but allows others to continue executing.

Specified by:
write in interface Stream
Throws:
IOException - if an error occurs writing to the stream.

read

public int read()
         throws IOException
Description copied from interface: Stream
Read in a single byte from the stream.

Specified by:
read in interface Stream
Returns:
The byte read in the low 8 bits of the returned value, or -1 if the stream has closed.
Throws:
IOException - if an error occurs reading from the stream.

write

public void write(int value)
           throws IOException
Description copied from interface: Stream
Write out a single byte to the stream.

Specified by:
write in interface Stream
Throws:
IOException - if an error occurs writing to the stream.

getException

public IOException getException(String defaultText)

throwIOException

public void throwIOException(String defaultText)
                      throws IOException
Throws:
IOException

toOutputStream

public OutputStream toOutputStream()
                            throws IllegalStateException
Specified by:
toOutputStream in interface Stream
Throws:
IllegalStateException

toInputStream

public InputStream toInputStream()
                          throws IllegalStateException
Specified by:
toInputStream in interface Stream
Throws:
IllegalStateException