ewe.io
Interface BasicStream

All Known Subinterfaces:
BasicRandomAccessStream, BufferedStream, RandomAccessStream, Stream
All Known Implementing Classes:
BasicStreamObject, RandomStreamAdapter, RandomStreamObject, StreamAdapter

public interface BasicStream

A BasicStream is a non-blocking Streaming interface. The only blocking method in it is close(). You would hardly use this interface directly, it is generally only used by native methods that require a non-blocking interface, since native methods cannot pause a running Thread without blocking the entire VM.


Method Summary
 boolean close()
          Closes the stream.
 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[] 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.
 

Method Detail

nonBlockingRead

public int nonBlockingRead(byte[] buff,
                           int start,
                           int count)
This is the non-blocking read operation. It should never attempt to wait() or sleep() in a Coroutine. It should return as quickly as possible. This makes it safe to be called from within a native method. Note that this should NEVER be called with a count of zero.

Parameters:
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.
Returns:
greater than 0 = Number of bytes read.
0 = No bytes available to read at this time.
-1 = Stream end reached no further bytes to read.
-2 = IO Error.

nonBlockingWrite

public int nonBlockingWrite(byte[] buff,
                            int start,
                            int count)
This is the non-blocking write operation. It should never attempt to wait() or sleep() in a Coroutine. It should return as quickly as possible. This makes it safe to be called from within a native method.

Parameters:
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.
Returns:
greater than 0 = Number of bytes actually written.
0 = No bytes could be written yet - but the stream is still open.
-1 = Stream has been closed - no further writes are possible.
-2 = IO error .

close

public boolean close()
Closes the stream. Returns true if the operation is successful and false otherwise.


isOpen

public boolean isOpen()
Returns if the stream is open or not.


flushStream

public boolean flushStream()
                    throws IOException
This is non-blocking. It returns true if the flush completed, false if it did not, or throws an exception on error.

Throws:
IOException

closeStream

public boolean closeStream()
                    throws IOException
This is non-blocking. It returns true if the close completed, false if it did not, or throws an exception on error.

Throws:
IOException