Package com.tangosol.io.nio
Class ByteBufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.tangosol.io.nio.ByteBufferOutputStream
-
- All Implemented Interfaces:
com.oracle.coherence.common.io.OutputStreaming,OutputStreaming,Closeable,Flushable,AutoCloseable
public class ByteBufferOutputStream extends OutputStream implements OutputStreaming
An OutputStream implementation on top of a Java NIO ByteBuffer.- Since:
- Coherence 2.2
- Author:
- cp 2002.09.06
-
-
Constructor Summary
Constructors Constructor Description ByteBufferOutputStream(ByteBuffer buffer)Construct a ByteBufferOutputStream on a ByteBuffer object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the stream, flushing any accumulated bytes.voidflush()Flush any accumulated bytes.ByteBuffergetByteBuffer()Obtain the ByteBuffer that this OutputStream is based on.protected static StringincludeMessage(Throwable e)Provide a "suffix" containing the exception message (if any).protected NullPointerExceptionpotentialStreamClosedException(NullPointerException e)Check if an NPE is caused by the stream being closed.voidwrite(byte[] abSrc, int ofSrc, int cbSrc)Writeslenbytes from the specified byte array starting at offsetoffto this output stream.voidwrite(int b)Writes the specified byte to this output stream.-
Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
-
-
-
Constructor Detail
-
ByteBufferOutputStream
public ByteBufferOutputStream(ByteBuffer buffer)
Construct a ByteBufferOutputStream on a ByteBuffer object.- Parameters:
buffer- the ByteBuffer to write the data to
-
-
Method Detail
-
getByteBuffer
public ByteBuffer getByteBuffer()
Obtain the ByteBuffer that this OutputStream is based on.- Returns:
- the underlying ByteBuffer
-
write
public void write(int b) throws IOExceptionWrites the specified byte to this output stream.- Specified by:
writein interfacecom.oracle.coherence.common.io.OutputStreaming- Specified by:
writein classOutputStream- Parameters:
b- thebyte- Throws:
IOException- if an I/O error occurs
-
write
public void write(byte[] abSrc, int ofSrc, int cbSrc) throws IOExceptionWriteslenbytes from the specified byte array starting at offsetoffto this output stream.If
bisnull, aNullPointerExceptionis thrown.If
offis negative, orlenis negative, oroff+lenis greater than the length of the arrayb, then an IndexOutOfBoundsException is thrown.- Specified by:
writein interfacecom.oracle.coherence.common.io.OutputStreaming- Overrides:
writein classOutputStream- Parameters:
abSrc- the dataofSrc- the start offset in the datacbSrc- the number of bytes to write- Throws:
IOException- if an I/O error occurs
-
flush
public void flush() throws IOExceptionFlush any accumulated bytes.- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfacecom.oracle.coherence.common.io.OutputStreaming- Overrides:
flushin classOutputStream- Throws:
IOException- if an I/O error occurs
-
close
public void close() throws IOExceptionClose the stream, flushing any accumulated bytes. The underlying buffer is not closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfacecom.oracle.coherence.common.io.OutputStreaming- Overrides:
closein classOutputStream- Throws:
IOException- if an I/O error occurs
-
includeMessage
protected static String includeMessage(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 NullPointerException potentialStreamClosedException(NullPointerException e) throws 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:
IOException- if the stream is closed
-
-