Package org.serviceconnector.util
Class CircularByteBuffer.CircularByteBufferInputStream
java.lang.Object
java.io.InputStream
org.serviceconnector.util.CircularByteBuffer.CircularByteBufferInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
- CircularByteBuffer
Class for reading from a circular byte buffer.
- Since:
- ostermillerutils 1.00.00
-
Constructor Summary
Constructors -
Method Summary
Modifier 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.voidmark(int readAheadLimit) Mark the present position in the stream.booleanTell whether this stream supports the mark() operation.intread()Read a single byte.intread(byte[] cbuf) Read bytes into an array.intread(byte[] cbuf, int off, int len) Read bytes into a portion of an array.voidreset()Reset the stream.longskip(long n) Skip bytes.Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
CircularByteBufferInputStream
protected CircularByteBufferInputStream()
-
-
Method Details
-
available
Returns 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.- Overrides:
availablein classInputStream- Returns:
- the number of bytes that can be read from this input stream without blocking.
- Throws:
IOException- if the stream is closed.- Since:
- ostermillerutils 1.00.00
-
close
Close the stream. Once a stream has been closed, further read(), available(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- never.- Since:
- ostermillerutils 1.00.00
-
mark
public void mark(int readAheadLimit) Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.The readAheadLimit must be less than the size of circular buffer, otherwise this method has no effect.
- Overrides:
markin classInputStream- Parameters:
readAheadLimit- Limit on the number of bytes that may be read while still preserving the mark. After reading this many bytes, attempting to reset the stream will fail.- Since:
- ostermillerutils 1.00.00
-
markSupported
public boolean markSupported()Tell whether this stream supports the mark() operation.- Overrides:
markSupportedin classInputStream- Returns:
- true, mark is supported.
- Since:
- ostermillerutils 1.00.00
-
read
Read a single byte. This method will block until a byte is available, an I/O error occurs, or the end of the stream is reached.- Specified by:
readin classInputStream- Returns:
- The byte read, as an integer in the range 0 to 255 (0x00-0xff), or -1 if the end of the stream has been reached
- Throws:
IOException- if the stream is closed.- Since:
- ostermillerutils 1.00.00
-
read
Read bytes into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.- Overrides:
readin classInputStream- Parameters:
cbuf- Destination buffer.- Returns:
- The number of bytes read, or -1 if the end of the stream has been reached
- Throws:
IOException- if the stream is closed.- Since:
- ostermillerutils 1.00.00
-
read
Read bytes into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.- Overrides:
readin classInputStream- Parameters:
cbuf- Destination buffer.off- Offset at which to start storing bytes.len- Maximum number of bytes to read.- Returns:
- The number of bytes read, or -1 if the end of the stream has been reached
- Throws:
IOException- if the stream is closed.- Since:
- ostermillerutils 1.00.00
-
reset
Reset the stream. If the stream has been marked, then attempt to reposition i at the mark. If the stream has not been marked, or more bytes than the readAheadLimit have been read, this method has no effect.- Overrides:
resetin classInputStream- Throws:
IOException- if the stream is closed.- Since:
- ostermillerutils 1.00.00
-
skip
Skip bytes. This method will block until some bytes are available, an I/O error occurs, or the end of the stream is reached.- Overrides:
skipin classInputStream- Parameters:
n- The number of bytes to skip- Returns:
- The number of bytes actually skipped
- Throws:
IllegalArgumentException- if n is negative.IOException- if the stream is closed.- Since:
- ostermillerutils 1.00.00
-