| Modifier and Type | Class and Description |
|---|---|
| pack-priv static interface | ResizingPipedInputStream.
Handler of notifications provided by the ResizingPipedInputStream. |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int | |
| private byte[] | buffer
The raw buffer. |
| private ByteBuffer | byteBuffer
View to the raw buffer. |
| private int | |
| private final int | initialBufferSize
The initial size of the buffer and the number of bytes by which the size of the buffer will increase each time it grows, unless it must grow by a smaller amount to fit within 'maximumBufferSize'. |
| private final int | maximumBufferSize
The maximum size of the buffer. |
| private static final ResizingPipedInputStream. | NO_OP_NOTIFICATION_CONSUMER
A NotificationConsumer that does nothing. |
| private ResizingPipedInputStream. | notificationConsumer
The NotificationConsumer currently registered. |
| private int | readIndex
The index of the next byte in the buffer that is available to be read. |
| private static final int | SINGLE_BYTE_MASK
Mask to isolate a single byte. |
| private int | |
| private final boolean | useBoundary
Whether to use a boundary to limit the number of available bytes. |
| private int | writeIndex
The index at which the next byte received will be written. |
| Access | Constructor and Description |
|---|---|
| public | ResizingPipedInputStream(final int
the initial size of the buffer. When full, the buffer will grow by this
many bytes. The buffer always stores bytes contiguously, so growth requires
allocation of a new buffer capable of holding the new capacity and copying of the
existing bytes into the new buffer. As such, a size should be chosen carefully
such that growth is expected to occur rarely, if ever. initialBufferSize)Constructor. |
| pack-priv | ResizingPipedInputStream(final int
the initial size of the buffer. When full, the buffer will grow by this
many bytes. The buffer always stores bytes contiguously, so growth requires
allocation of a new buffer capable of holding the new capacity and copying of the
existing bytes into the new buffer. As such, a size should be chosen carefully
such that growth is expected to occur rarely, if ever. initialBufferSize, final int the maximum size of the buffer. If a call to `receive` attempts to transfer an amount
of bytes that would cause the buffer to exceed this size, a
maximumBufferSize, final boolean BufferOverflowException will be thrown. Must be greater than or equal to the
initial buffer size.whether to use a boundary to limit the number of available bytes. This can be used to buffer
arbitrarily-sized chunks of bytes without making them available for consumption. When true,
the boundary must be manually extended (see useBoundary)extendBoundary(int) to make these bytes
available. When false, all buffered bytes will be available to read.Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: the exact number of bytes available in the buffer.Overrides java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. |
| pack-priv int | Returns: the number of bytes buffered beyond the boundary. This is equivalent to subtractingavailable()
from size().
|
| public int | Returns: the capacity of the buffer, which is always less than or equal to 'maximumBufferSize'.
|
| pack-priv void | |
| pack-priv void | consolidate(int
the position to move bytes from. Must be less than or equal to 'writeIndex' and 'boundary'. fromPosition, int the position to move bytes to. Must be greater than or equal to 'readIndex'. toPosition)Moves all bytes starting at 'fromPosition' to 'toPosition', overwriting the bytes in-between. |
| pack-priv void | copyBytes(int
the start position from which to read. position, byte[] the buffer to copy into. destination, int the offset of the buffer to copy into. destinationOffset, int the number of bytes to copy. length)Copies bytes from the underlying buffer. |
| public void | copyTo(final OutputStream
stream to which the bytes will be copied. outputStream)Copies all of the available bytes in the buffer without changing the number of bytes available to subsequent reads. |
| private void | ensureSpaceInBuffer(int
the minimum amount of free space that needs to be available for writing. minimumNumberOfBytesRequired)Ensures that there is at least 'minimumNumberOfBytesRequired' bytes of free space in the buffer, growing the buffer if necessary. |
| pack-priv void | extendBoundary(int
the number of bytes by which the boundary should be extended. numberOfBytes)Extends the boundary by the given number of bytes. |
| private int | |
| pack-priv int | Returns: the index of the boundary, which is used to mark the last buffered byte that is available for reading. The boundary must always fall within [readIndex, writeIndex].
|
| pack-priv ByteBuffer | Returns: a ByteBuffer.the start position of the ByteBuffer. position, int the limit of the ByteBuffer. limit)Returns a ByteBuffer view of the underlying buffer. |
| pack-priv int | |
| pack-priv int | |
| pack-priv int | |
| private void | moveBytesToStartOfBuffer(byte[]
the destination buffer, which may be 'buffer' itself or a new buffer. destinationBuffer)Moves all buffered (but not yet read) bytes from 'buffer' to the destination buffer. |
| pack-priv int | Returns: the byte value.the index of the byte to peek. index)Peeks the byte at the given index without modifying any internal indexes. |
| public int | read(final byte[]
the buffer into which the data is read. b, final int the start offset in array off, final int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to |
| public int | read()
Implements abstract java. Reads the next byte of data from the input stream. |
| public void | receive(final int
the byte to buffer. b)Buffers a single additional byte, growing the buffer if it is already full. |
| public void | receive(final byte[]
the bytes to buffer. b, final int the offset into `b` that points to the first byte to buffer. off, final int the number of bytes to buffer. len)Buffers `len` additional bytes, growing the buffer if it is already full or if it would become full by writing `len` bytes. |
| public void | |
| public int | Returns: the number of bytes actually written, which will only be less than `len` ifInputStream#read(byte[], int, int) returns less than `len`.the source of the bytes. input, final int the number of bytes to attempt to write. len)Buffers up to `len` additional bytes, growing the buffer if it is already full or if it would become full by writing `len` bytes. |
| pack-priv void | registerNotificationConsumer(ResizingPipedInputStream.
the NotificationConsumer to register. consumerRegisters the given NotificationConsumer. |
| pack-priv void | rewind(final int
the read index value to be set. previousReadIndex, final int the available value to be set. previousAvailable)Rewinds the buffer to the given read index and sets 'available' to the given value. |
| pack-priv void | seekTo(int
the index to which to seek. Must not be negative. index)Seeks the read index to the given position. |
| pack-priv int | Returns: the number of bytes actually buffered, which will be greater than or equal to 'available' if a boundary has been set, or equal to `available` if no boundary has been set.
|
| public long | Returns: the number of bytes actually skipped.the number of bytes to skip. n)Overrides java. Skips up to `n` buffered bytes. |
| pack-priv void | truncate(final int
the write index value to be set. previousWriteIndex, final int the available value to be set. previousAvailable)Truncates the buffer to the given write index and sets both 'available' and 'size' to the to the given value. |
| available | back to summary |
|---|---|
private int available
| |
| boundary | back to summary |
|---|---|
private int boundary
| |
| buffer | back to summary |
|---|---|
| private byte[] buffer The raw buffer. | |
| byteBuffer | back to summary |
|---|---|
| private ByteBuffer byteBuffer View to the raw buffer. | |
| capacity | back to summary |
|---|---|
private int capacity
| |
| initialBufferSize | back to summary |
|---|---|
| private final int initialBufferSize The initial size of the buffer and the number of bytes by which the size of the buffer will increase each time it grows, unless it must grow by a smaller amount to fit within 'maximumBufferSize'. | |
| maximumBufferSize | back to summary |
|---|---|
| private final int maximumBufferSize The maximum size of the buffer. If the user attempts to buffer more bytes than this, an exception will be raised. | |
| NO_OP_NOTIFICATION_CONSUMER | back to summary |
|---|---|
| private static final ResizingPipedInputStream. A NotificationConsumer that does nothing. | |
| notificationConsumer | back to summary |
|---|---|
| private ResizingPipedInputStream. The NotificationConsumer currently registered. | |
| readIndex | back to summary |
|---|---|
| private int readIndex The index of the next byte in the buffer that is available to be read. Always less than or equal to `writeIndex`. | |
| SINGLE_BYTE_MASK | back to summary |
|---|---|
| private static final int SINGLE_BYTE_MASK Mask to isolate a single byte. | |
| size | back to summary |
|---|---|
private int size
| |
| useBoundary | back to summary |
|---|---|
| private final boolean useBoundary Whether to use a boundary to limit the number of available bytes. This can be used to buffer
arbitrarily-sized chunks of bytes without making them available for consumption. When true,
the boundary must be manually extended (see | |
| writeIndex | back to summary |
|---|---|
| private int writeIndex The index at which the next byte received will be written. Always greater than or equal to `readIndex`. | |
| ResizingPipedInputStream | back to summary |
|---|---|
| public ResizingPipedInputStream(final int initialBufferSize) Constructor.
| |
| ResizingPipedInputStream | back to summary |
|---|---|
| pack-priv ResizingPipedInputStream(final int initialBufferSize, final int maximumBufferSize, final boolean useBoundary) Constructor.
| |
| available | back to summary |
|---|---|
| public int available() Overrides java. Doc from java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of A subclass's implementation of this method may choose to throw an
Note This method adheres to the documented behavior of
| |
| availableBeyondBoundary | back to summary |
|---|---|
pack-priv int availableBeyondBoundary()
| |
| capacity | back to summary |
|---|---|
public int capacity()
| |
| clear | back to summary |
|---|---|
| pack-priv void clear() Clears the buffer. | |
| consolidate | back to summary |
|---|---|
| pack-priv void consolidate(int fromPosition, int toPosition) Moves all bytes starting at 'fromPosition' to 'toPosition', overwriting the bytes in-between. It is the caller's responsibility to ensure that the overwritten bytes are not needed.
| |
| copyBytes | back to summary |
|---|---|
| pack-priv void copyBytes(int position, byte[] destination, int destinationOffset, int length) Copies bytes from the underlying buffer. It is the caller's responsibility to ensure the requested bytes are available.
| |
| copyTo | back to summary |
|---|---|
| public void copyTo(final OutputStream outputStream) throws IOException Copies all of the available bytes in the buffer without changing the number of bytes available to subsequent reads.
| |
| ensureSpaceInBuffer | back to summary |
|---|---|
| private void ensureSpaceInBuffer(int minimumNumberOfBytesRequired) Ensures that there is at least 'minimumNumberOfBytesRequired' bytes of free space in the buffer, growing the buffer if necessary. May consolidate buffered bytes, performing an in-order copy and resetting indices such that the `readIndex` points to the same byte and the `writeIndex` is positioned after the last byte that is available to read.
| |
| extendBoundary | back to summary |
|---|---|
| pack-priv void extendBoundary(int numberOfBytes) Extends the boundary by the given number of bytes. It is the caller's responsibility to ensure that the resulting boundary includes only bytes that have been buffered (i.e. that it does not exceed `writeIndex`).
| |
| freeSpaceAtEndOfBuffer | back to summary |
|---|---|
private int freeSpaceAtEndOfBuffer()
| |
| getBoundary | back to summary |
|---|---|
pack-priv int getBoundary()
| |
| getByteBuffer | back to summary |
|---|---|
| pack-priv ByteBuffer getByteBuffer(int position, int limit) Returns a ByteBuffer view of the underlying buffer.
| |
| getInitialBufferSize | back to summary |
|---|---|
pack-priv int getInitialBufferSize()
| |
| getReadIndex | back to summary |
|---|---|
pack-priv int getReadIndex()
| |
| getWriteIndex | back to summary |
|---|---|
pack-priv int getWriteIndex()
| |
| moveBytesToStartOfBuffer | back to summary |
|---|---|
| private void moveBytesToStartOfBuffer(byte[] destinationBuffer) Moves all buffered (but not yet read) bytes from 'buffer' to the destination buffer. In total,
| |
| peek | back to summary |
|---|---|
| pack-priv int peek(int index) Peeks the byte at the given index without modifying any internal indexes. It is the caller's responsibility to ensure that the given index points to an available byte.
| |
| read | back to summary |
|---|---|
| public int read(final byte[] b, final int off, final int len) Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements Note This method adheres to the documented behavior of
| |
| read | back to summary |
|---|---|
| public int read() Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an Note This method adheres to the documented behavior of
| |
| receive | back to summary |
|---|---|
| public void receive(final int b) Buffers a single additional byte, growing the buffer if it is already full.
| |
| receive | back to summary |
|---|---|
| public void receive(final byte[] b, final int off, final int len) Buffers `len` additional bytes, growing the buffer if it is already full or if it would become full by writing `len` bytes.
| |
| receive | back to summary |
|---|---|
| public void receive(final byte[] b) Buffers `b.length` additional bytes.
| |
| receive | back to summary |
|---|---|
| public int receive(final InputStream input, final int len) throws IOException Buffers up to `len` additional bytes, growing the buffer if it is already full or if it would become full
by writing `len` bytes. This method will block if and only if the given `InputStream`'s
| |
| registerNotificationConsumer | back to summary |
|---|---|
| pack-priv void registerNotificationConsumer(ResizingPipedInputStream. Registers the given NotificationConsumer.
| |
| rewind | back to summary |
|---|---|
| pack-priv void rewind(final int previousReadIndex, final int previousAvailable) Rewinds the buffer to the given read index and sets 'available' to the given value. Subsequent
behavior is undefined unless the values resulted from calling
| |
| seekTo | back to summary |
|---|---|
| pack-priv void seekTo(int index) Seeks the read index to the given position.
| |
| size | back to summary |
|---|---|
pack-priv int size()
| |
| skip | back to summary |
|---|---|
| public long skip(final long n) Overrides java. Skips up to `n` buffered bytes. Less than `n` bytes will be skipped if less than `n` bytes are available in the buffer.
| |
| truncate | back to summary |
|---|---|
| pack-priv void truncate(final int previousWriteIndex, final int previousAvailable) Truncates the buffer to the given write index and sets both 'available' and 'size' to the to the given value.
Subsequent behavior is undefined unless the values resulted from calling
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | bytesConsolidatedToStartOfBuffer(int
the amount of the left shift (also: the pre-shift read index of the first shifted
byte). leftShiftAmount)Bytes have been shifted to the start of the buffer in order to make room for additional bytes to be buffered. |
| bytesConsolidatedToStartOfBuffer | back to summary |
|---|---|
| public void bytesConsolidatedToStartOfBuffer(int leftShiftAmount) Bytes have been shifted to the start of the buffer in order to make room for additional bytes to be buffered.
| |