Oracle® Coherence Java API Reference
v3.5

E14977-01

com.tangosol.io.nio
Class ByteBufferOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.tangosol.io.nio.ByteBufferOutputStream
All Implemented Interfaces:
OutputStreaming, java.io.Closeable, java.io.Flushable

public class ByteBufferOutputStream
extends java.io.OutputStream
implements OutputStreaming

An OutputStream implementation on top of a Java NIO ByteBuffer.

Since:
Coherence 2.2
Author:
cp 2002.09.06

Constructor Summary
ByteBufferOutputStream(java.nio.ByteBuffer buffer)
          Construct a ByteBufferOutputStream on a ByteBuffer object.
 
Method Summary
 void close()
          Close the stream, flushing any accumulated bytes.
 void flush()
          Flush any accumulated bytes.
 java.nio.ByteBuffer getByteBuffer()
          Obtain the ByteBuffer that this OutputStream is based on.
protected static java.lang.String includeMessage(java.lang.Throwable e)
          Provide a "suffix" containing the exception message (if any).
protected  java.lang.NullPointerException potentialStreamClosedException(java.lang.NullPointerException e)
          Check if an NPE is caused by the stream being closed.
 void write(byte[] abSrc, int ofSrc, int cbSrc)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from interface com.tangosol.io.OutputStreaming
write
 

Constructor Detail

ByteBufferOutputStream

public ByteBufferOutputStream(java.nio.ByteBuffer buffer)
Construct a ByteBufferOutputStream on a ByteBuffer object.

Parameters:
buffer - the ByteBuffer to write the data to
Method Detail

getByteBuffer

public java.nio.ByteBuffer getByteBuffer()
Obtain the ByteBuffer that this OutputStream is based on.

Returns:
the underlying ByteBuffer

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this output stream.

Specified by:
write in interface OutputStreaming
Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte
Throws:
java.io.IOException - if an I/O error occurs

write

public void write(byte[] abSrc,
                  int ofSrc,
                  int cbSrc)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this output stream.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Specified by:
write in interface OutputStreaming
Overrides:
write in class java.io.OutputStream
Parameters:
abSrc - the data
ofSrc - the start offset in the data
cbSrc - the number of bytes to write
Throws:
java.io.IOException - if an I/O error occurs

flush

public void flush()
           throws java.io.IOException
Flush any accumulated bytes.

Specified by:
flush in interface OutputStreaming
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - if an I/O error occurs

close

public void close()
           throws java.io.IOException
Close the stream, flushing any accumulated bytes. The underlying buffer is not closed.

Specified by:
close in interface OutputStreaming
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - if an I/O error occurs

includeMessage

protected static java.lang.String includeMessage(java.lang.Throwable e)
Provide a "suffix" containing the exception message (if any).

Parameters:
e - an exception (any Throwable object)
Returns:
either an empty string (no message) or a suitable suffix for an error message

potentialStreamClosedException

protected java.lang.NullPointerException potentialStreamClosedException(java.lang.NullPointerException e)
                                                                 throws java.io.IOException
Check if an NPE is caused by the stream being closed. Either throws an IO exception if the stream is closed or throws the original NPE.

Parameters:
e - an NPE
Returns:
this method never returns normally but is designed so that the developer can write "throw potentialStreamClosedException(e)" so that the compiler knows that an exception is thrown at that point in the code
Throws:
java.io.IOException - if the stream is closed

Oracle® Coherence Java API Reference
v3.5

E14977-01

Copyright © 2000, 2009, Oracle. All rights reserved.