Package com.tangosol.io.nio
Class ByteBufferInputStream
java.lang.Object
java.io.InputStream
com.tangosol.io.nio.ByteBufferInputStream
- All Implemented Interfaces:
- com.oracle.coherence.common.io.InputStreaming,- InputStreaming,- Closeable,- AutoCloseable
An InputStream implementation on top of a Java NIO ByteBuffer.
- Since:
- Coherence 2.2
- Author:
- cp 2002.09.06
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ByteBufferThe ByteBuffer object from which data is read.
- 
Constructor SummaryConstructorsConstructorDescriptionByteBufferInputStream(ByteBuffer buffer) Construct a ByteBufferInputStream on a ByteBuffer object.
- 
Method SummaryModifier and TypeMethodDescriptionintReturns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.voidclose()Close the stream, flushing any accumulated bytes.Obtain the ByteBuffer that this InputStream is based on.voidmark(int readlimit) Marks the current position in this input stream.booleanTests if this input stream supports themarkandresetmethods.protected NullPointerExceptionCheck if an NPE is caused by the stream being closed.intread()Reads the next byte of data from the input stream.intread(byte[] abDest, int ofDest, int cbDest) Reads up tolenbytes of data from the input stream into an array of bytes.voidreset()Repositions this stream to the position at the time themarkmethod was last called on this input stream.longskip(long lcb) Skips over and discardsnbytes of data from this input stream.Methods inherited from class java.io.InputStreamnullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.oracle.coherence.common.io.InputStreamingread
- 
Field Details- 
m_bufThe ByteBuffer object from which data is read.
 
- 
- 
Constructor Details- 
ByteBufferInputStreamConstruct a ByteBufferInputStream on a ByteBuffer object.- Parameters:
- buffer- the ByteBuffer to read the data from
 
 
- 
- 
Method Details- 
getByteBufferObtain the ByteBuffer that this InputStream is based on.- Returns:
- the underlying ByteBuffer
 
- 
readReads the next byte of data from the input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Specified by:
- readin interface- com.oracle.coherence.common.io.InputStreaming
- Specified by:
- readin class- InputStream
- Returns:
- the next byte of data, or -1if the end of the stream is reached
- Throws:
- IOException- if an I/O error occurs
 
- 
readReads up tolenbytes of data from the input stream into an array of bytes. An attempt is made to read as many aslenbytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.- Specified by:
- readin interface- com.oracle.coherence.common.io.InputStreaming
- Overrides:
- readin class- InputStream
- Parameters:
- abDest- the buffer into which the data is read
- ofDest- the start offset in array- bat which the data is written
- cbDest- the maximum number of bytes to read
- Returns:
- the total number of bytes read into the buffer, or
         -1if there is no more data because the end of the stream has been reached.
- Throws:
- IOException- if an I/O error occurs
 
- 
skipSkips over and discardsnbytes of data from this input stream. Theskipmethod may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly0. This may result from any of a number of conditions; reaching end of file beforenbytes have been skipped is only one possibility. The actual number of bytes skipped is returned. Ifnis negative, no bytes are skipped.- Specified by:
- skipin interface- com.oracle.coherence.common.io.InputStreaming
- Overrides:
- skipin class- InputStream
- Parameters:
- lcb- the number of bytes to be skipped
- Returns:
- the actual number of bytes skipped
- Throws:
- IOException- if an I/O error occurs
 
- 
availableReturns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or or another thread.- Specified by:
- availablein interface- com.oracle.coherence.common.io.InputStreaming
- Overrides:
- availablein class- InputStream
- Returns:
- the number of bytes that can be read from this input stream without blocking.
- Throws:
- IOException- if an I/O error occurs
 
- 
markpublic void mark(int readlimit) Marks the current position in this input stream. A subsequent call to theresetmethod repositions this stream at the last marked position so that subsequent reads re-read the same bytes.- Specified by:
- markin interface- com.oracle.coherence.common.io.InputStreaming
- Overrides:
- markin class- InputStream
- Parameters:
- readlimit- the maximum limit of bytes that can be read before the mark position becomes invalid
 
- 
resetRepositions this stream to the position at the time themarkmethod was last called on this input stream.- Specified by:
- resetin interface- com.oracle.coherence.common.io.InputStreaming
- Overrides:
- resetin class- InputStream
- Throws:
- IOException- if an I/O error occurs.
 
- 
markSupportedpublic boolean markSupported()Tests if this input stream supports themarkandresetmethods. ThemarkSupportedmethod ofInputStreamreturnsfalse.- Specified by:
- markSupportedin interface- com.oracle.coherence.common.io.InputStreaming
- Overrides:
- markSupportedin class- InputStream
- Returns:
- trueif this true type supports the mark and reset method;- falseotherwise
 
- 
closeClose the stream, flushing any accumulated bytes. The underlying buffer is not closed.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- com.oracle.coherence.common.io.InputStreaming
- Overrides:
- closein class- InputStream
- Throws:
- IOException- if an I/O error occurs.
 
- 
potentialStreamClosedExceptionprotected 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
 
 
-