com.Ostermiller.util
Class CircularByteBuffer.CircularByteBufferOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.Ostermiller.util.CircularByteBuffer.CircularByteBufferOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Enclosing class:
CircularByteBuffer

protected class CircularByteBuffer.CircularByteBufferOutputStream
extends java.io.OutputStream

Class for writing to a circular byte buffer. If the buffer is full, the writes will either block until there is some space available or throw an IOException based on the CircularByteBuffer's preference.

Since:
ostermillerutils 1.00.00

Constructor Summary
protected CircularByteBuffer.CircularByteBufferOutputStream()
           
 
Method Summary
 void close()
          Close the stream, flushing it first.
 void flush()
          Flush the stream.
 void write(byte[] cbuf)
          Write an array of bytes.
 void write(byte[] cbuf, int off, int len)
          Write a portion of an array of bytes.
 void write(int c)
          Write a single byte.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CircularByteBuffer.CircularByteBufferOutputStream

protected CircularByteBuffer.CircularByteBufferOutputStream()
Method Detail

close

public void close()
           throws java.io.IOException
Close the stream, flushing it first. This will cause the InputStream associated with this circular buffer to read its last bytes once it empties the buffer. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - never.
Since:
ostermillerutils 1.00.00

flush

public void flush()
           throws java.io.IOException
Flush the stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00

write

public void write(byte[] cbuf)
           throws java.io.IOException
Write an array of bytes. If the buffer allows blocking writes, this method will block until all the data has been written rather than throw an IOException.

Overrides:
write in class java.io.OutputStream
Parameters:
cbuf - Array of bytes to be written
Throws:
BufferOverflowException - if buffer does not allow blocking writes and the buffer is full. If the exception is thrown, no data will have been written since the buffer was set to be non-blocking.
java.io.IOException - if the stream is closed, or the write is interrupted.
Since:
ostermillerutils 1.00.00

write

public void write(byte[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Write a portion of an array of bytes. If the buffer allows blocking writes, this method will block until all the data has been written rather than throw an IOException.

Overrides:
write in class java.io.OutputStream
Parameters:
cbuf - Array of bytes
off - Offset from which to start writing bytes
len - - Number of bytes to write
Throws:
BufferOverflowException - if buffer does not allow blocking writes and the buffer is full. If the exception is thrown, no data will have been written since the buffer was set to be non-blocking.
java.io.IOException - if the stream is closed, or the write is interrupted.
Since:
ostermillerutils 1.00.00

write

public void write(int c)
           throws java.io.IOException
Write a single byte. The byte to be written is contained in the 8 low-order bits of the given integer value; the 24 high-order bits are ignored. If the buffer allows blocking writes, this method will block until all the data has been written rather than throw an IOException.

Specified by:
write in class java.io.OutputStream
Parameters:
c - number of bytes to be written
Throws:
BufferOverflowException - if buffer does not allow blocking writes and the buffer is full.
java.io.IOException - if the stream is closed, or the write is interrupted.
Since:
ostermillerutils 1.00.00