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
An OutputStream implementation on top of a Java NIO ByteBuffer.
- Since:
- Coherence 2.2
- Author:
- cp 2002.09.06
-
Constructor Summary
ConstructorDescriptionByteBufferOutputStream
(ByteBuffer buffer) Construct a ByteBufferOutputStream on a ByteBuffer object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the stream, flushing any accumulated bytes.void
flush()
Flush any accumulated bytes.Obtain the ByteBuffer that this OutputStream is based on.protected static String
Provide a "suffix" containing the exception message (if any).protected NullPointerException
Check if an NPE is caused by the stream being closed.void
write
(byte[] abSrc, int ofSrc, int cbSrc) Writeslen
bytes from the specified byte array starting at offsetoff
to this output stream.void
write
(int b) Writes the specified byte to this output stream.Methods inherited from class java.io.OutputStream
nullOutputStream, write
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.oracle.coherence.common.io.OutputStreaming
write
-
Constructor Details
-
ByteBufferOutputStream
Construct a ByteBufferOutputStream on a ByteBuffer object.- Parameters:
buffer
- the ByteBuffer to write the data to
-
-
Method Details
-
getByteBuffer
Obtain the ByteBuffer that this OutputStream is based on.- Returns:
- the underlying ByteBuffer
-
write
Writes the specified byte to this output stream.- Specified by:
write
in interfacecom.oracle.coherence.common.io.OutputStreaming
- Specified by:
write
in classOutputStream
- Parameters:
b
- thebyte
- Throws:
IOException
- if an I/O error occurs
-
write
Writeslen
bytes from the specified byte array starting at offsetoff
to this output stream.If
b
isnull
, aNullPointerException
is thrown.If
off
is negative, orlen
is negative, oroff+len
is greater than the length of the arrayb
, then an IndexOutOfBoundsException is thrown.- Specified by:
write
in interfacecom.oracle.coherence.common.io.OutputStreaming
- Overrides:
write
in 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
Flush any accumulated bytes.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfacecom.oracle.coherence.common.io.OutputStreaming
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- if an I/O error occurs
-
close
Close the stream, flushing any accumulated bytes. The underlying buffer is not closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfacecom.oracle.coherence.common.io.OutputStreaming
- Overrides:
close
in classOutputStream
- Throws:
IOException
- if an I/O error occurs
-
includeMessage
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
-