seda.nbio
Class NonblockingOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by seda.nbio.NonblockingOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
NonblockingSocketOutputStream

public abstract class NonblockingOutputStream
extends java.io.OutputStream

A NonblockingOutputStream is an OutputStream with nonblocking semantics. The various write() methods are blocking, while the nbWrite() methods are nonblocking. It was necessary to introduce new methods as the original write() calls return void, and hence there is no way to indicate that only a portion of the request was written.


Constructor Summary
NonblockingOutputStream()
           
 
Method Summary
abstract  void close()
           
abstract  void flush()
          Flush the underlying output stream.
abstract  int nbWrite(byte b)
          Perform a non-blocking write of one byte to this output stream.
abstract  int nbWrite(byte[] b)
          Perform a nonblocking write of up to b.length bytes to the underlying stream.
abstract  int nbWrite(byte[] b, int off, int len)
          Perform a nonblocking write of up to len bytes to the underlying stream starting at offset off.
abstract  void write(byte[] b)
          Perform a blocking write of b.length bytes to the underlying stream.
abstract  void write(byte[] b, int off, int len)
          Perform a blocking write of len bytes to the underlying stream from the byte array b starting at offset off.
abstract  void write(int b)
          Perform a blocking write of one byte to this output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonblockingOutputStream

public NonblockingOutputStream()
Method Detail

write

public abstract void write(int b)
                    throws java.io.IOException
Perform a blocking write of one byte to this output stream. Throws an EOFException if the end of stream has been reached. Use nbWrite() to perform a non-blocking write of one byte.

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public abstract void write(byte[] b)
                    throws java.io.IOException
Perform a blocking write of b.length bytes to the underlying stream. Use nbWrite() to perform a nonblocking write.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public abstract void write(byte[] b,
                           int off,
                           int len)
                    throws java.io.IOException
Perform a blocking write of len bytes to the underlying stream from the byte array b starting at offset off. Use nbWrite() to perform a nonblocking write.

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

nbWrite

public abstract int nbWrite(byte b)
                     throws java.io.IOException
Perform a non-blocking write of one byte to this output stream. Returns 1 if the data was written or 0 if it could not be. Throws an EOFException if the end of the stream has been reached. Use write() to perform a blocking write of one byte.

Throws:
java.io.IOException

nbWrite

public abstract int nbWrite(byte[] b)
                     throws java.io.IOException
Perform a nonblocking write of up to b.length bytes to the underlying stream. Returns the number of bytes written, or 0 if nothing was written. Use write() to perform a blocking write.

Throws:
java.io.IOException

nbWrite

public abstract int nbWrite(byte[] b,
                            int off,
                            int len)
                     throws java.io.IOException
Perform a nonblocking write of up to len bytes to the underlying stream starting at offset off. Returns the number of bytes written, or 0 if nothing was written. Use write() to perform a blocking write.

Throws:
java.io.IOException

flush

public abstract void flush()
Flush the underlying output stream. This is a blocking operation.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream

close

public abstract void close()
                    throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException