public class ByteArrayInputStream extends InputStream
InputStream
for reading the contents of a byte array.Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf
The
byte array containing the bytes to stream over. |
protected int |
count
The total number of bytes initially available in the byte array
buf . |
protected int |
pos
The current position within the byte array.
|
Constructor and Description |
---|
ByteArrayInputStream(byte[] buf)
Constructs a new
ByteArrayInputStream on the byte array buf . |
ByteArrayInputStream(byte[] buf,
int offset,
int length)
Constructs a new
ByteArrayInputStream on the byte array buf with the initial position set to
offset and the number of bytes available set to offset + length . |
ByteArrayInputStream(ByteArrayRange byteArrayRange)
Constructs a new
ByteArrayInputStream on the byte array range. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this stream.
|
int |
read()
Reads a single byte from the source byte array and returns it as an integer in the range from 0 to 255.
|
int |
read(byte[] b,
int offset,
int length)
Reads at most
len bytes from this stream and stores them in byte array b starting at offset . |
copyTo, copyToByteArray, finalize, read, readFully, readFully
protected byte[] buf
byte
array containing the bytes to stream over.protected int pos
protected int count
buf
.public ByteArrayInputStream(byte[] buf)
ByteArrayInputStream
on the byte array buf
.buf
- the byte array to stream over.public ByteArrayInputStream(ByteArrayRange byteArrayRange)
ByteArrayInputStream
on the byte array range.byteArrayRange
- the byte array range to stream overpublic ByteArrayInputStream(byte[] buf, int offset, int length)
ByteArrayInputStream
on the byte array buf
with the initial position set to
offset
and the number of bytes available set to offset
+ length
.buf
- the byte array to stream over.offset
- the initial position in buf
to start streaming from.length
- the number of bytes available for streaming.public void close()
InputStream
close
in interface java.lang.AutoCloseable
close
in class InputStream
public int read()
read
in class InputStream
public int read(byte[] b, int offset, int length)
len
bytes from this stream and stores them in byte array b
starting at offset
. This implementation reads bytes from the source byte array.read
in class InputStream
b
- the byte array in which to store the bytes readoffset
- the initial position in b
to store the bytes read from this streamlength
- the maximum number of bytes to store in b