public final class FastBufferedInputStream
extends java.io.InputStream
InputStream that uses the enclosing instance's
InputStream its data source. This is not supposed to be a general purpose
implementation.| Modifier and Type | Field and Description |
|---|---|
private byte[] |
buffer
data buffer (cache)
|
private java.io.InputStream |
in
underying input stream
|
private byte[] |
iobuffer
underlying input stream read buffer -- the size of this buffer determines the
maximum bytes read
|
(package private) int |
maxRead
Note:
Breaks the contract of the InputStream.read(byte[], int, int)
to the extent that call will block on the underlying InputStream
until it gets all the len bytes specified. |
private int |
offset
current (read) offset of
buffer |
| Constructor and Description |
|---|
FastBufferedInputStream(java.io.InputStream in,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
private int |
getMoreBytes(int len)
Get more bytes from the underling
InputStream. |
boolean |
markSupported()
InputStream.mark(int) is not supported. |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
private byte[] buffer
private int offset
bufferprivate final byte[] iobuffer
private final java.io.InputStream in
int maxRead
InputStream.read(byte[], int, int)
to the extent that call will block on the underlying InputStream
until it gets all the len bytes specified.
Also, this call will return -1 if and only if it (a) needs to get more
data by calling getMoreBytes(int),
and (b) that call returns -1. Note that it is possible, in a general
context, that -1 is returned but there is previously accumulated data in
buffer and thus
available() returns a non zero positive
integer which is less than specified len. But that is not expected
in the specific context of Redis protocol.
InputStream.read(byte[], int, int)public FastBufferedInputStream(java.io.InputStream in,
int bufferSize)
in - the input sourcebufferSize - size of the iobufferprivate final int getMoreBytes(int len)
throws java.io.IOException
InputStream.
Only reads from input source if len exceeds available data in
buffer.
This call will block until (minimally) len bytes have been read.
len - java.io.IOException - if a read on the underlying stream returns 0 length bytes.
This (obviously) shouldn't happen but if it does, it would be treated as an exception.public int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionInputStream.available()public boolean markSupported()
InputStream.mark(int) is not supported.markSupported in class java.io.InputStreamInputStream.markSupported()public int read(byte[] b)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException