public class ChunkyByteArrayInputStream extends InputStream
Constructor and Description |
---|
ChunkyByteArrayInputStream()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addBuffer(byte[] buf,
int length)
Be given a buffer full of input bytes.
|
int |
available()
Get the number of bytes that can be read from this input stream without
blocking.
|
void |
preserveBuffers()
Copy any unread portions of the client buffer passed to
addBuffer(byte[], int) . |
int |
read()
Read the next byte of data from the input stream.
|
String |
readASCIILine()
Read the next line of raw ASCII characters from the input stream.
|
int |
readByte()
Read the next raw byte of data from the input stream.
|
byte[] |
readBytes(int count)
Read a fixed number of bytes from the input stream.
|
int |
readUTF8Char()
Read the next UTF-8 encoded character from the input stream.
|
String |
readUTF8Line()
Read the next line of UTF-8 encoded characters from the input stream.
|
String |
readUTF8String(int byteCount)
Read a string of UTF-8 encoded characters from the input stream.
|
close, mark, markSupported, read, read, reset, skip
public ChunkyByteArrayInputStream()
public void addBuffer(byte[] buf, int length)
Note: this class assumes that it may continue to freely make direct
use of the contents of the byte buffer that is given to this method
(i.e., without copying it to internal storage) until preserveBuffers()
is called; after that, the buffer contents may be
modified externally. This is somewhat delicate, but eliminates a vast
amount of unnecessary byte array allocation and copying.
buf
- The bytes themselves.length
- Number of bytes in 'buf' to read (<= buf.length).public int available() throws IOException
available
in class InputStream
IOException
public void preserveBuffers()
addBuffer(byte[], int)
. This has the side effect of passing responsibility for the
client buffer back to the client. This indirection minimizes
unnecessary byte array allocation and copying.public int read() throws IOException
read
in class InputStream
IOException
- if an incomplete line is in the buffers upon the
true end of input.EOFException
- if the true end of input is reached normallypublic int readByte() throws IOException
IOException
- if the true end of input is reached normallypublic byte[] readBytes(int count) throws IOException
count
- The number of bytes desiredIOException
- if the true end of input is reached normallypublic int readUTF8Char() throws IOException
IOException
- if an incomplete line is in the buffers upon
encountering the true end of input.public String readASCIILine() throws IOException
Takes ASCII characters from the buffers until a newline (optionally preceded by a carriage return) is read, at which point the line is returned as a String, not including the line terminator character(s).
EOFException
- if the true end of input is reached.IOException
public String readUTF8Line() throws IOException
Takes UTF-8 characters from the buffers until a newline (optionally preceded by a carriage return) is read, at which point the line is returned as a String, not including the line terminator character(s).
EOFException
- if the true end of input is reached.IOException
public String readUTF8String(int byteCount) throws IOException
byteCount
- Number of bytes of "good" UTF-8 data known to be
available for reading.IOException
Copyright © 2017. All rights reserved.