public class FastByteArrayInputStream
extends java.io.InputStream
InputStream for reading the contents of a byte array.ByteArrayInputStream| 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 |
mark
The current mark position.
|
protected int |
pos
The current position within the byte array.
|
| Constructor and Description |
|---|
FastByteArrayInputStream(byte[] buf)
Constructs a new
ByteArrayInputStream on the byte array
buf. |
FastByteArrayInputStream(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. |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes that are available before this stream will
block.
|
void |
close()
Closes this stream and frees resources associated with this stream.
|
void |
mark(int readlimit)
Sets a mark position in this ByteArrayInputStream.
|
boolean |
markSupported()
Indicates whether this stream supports the
mark() and
reset() methods. |
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. |
void |
reset()
Resets this stream to the last marked location.
|
long |
skip(long n)
Skips
count number of bytes in this InputStream. |
protected byte[] buf
byte array containing the bytes to stream over.protected int pos
protected int mark
offset
parameter within the constructor.protected int count
buf.public FastByteArrayInputStream(byte[] buf)
ByteArrayInputStream on the byte array
buf.buf - the byte array to stream over.public FastByteArrayInputStream(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 int available()
available in class java.io.InputStreampublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOException - if an I/O error occurs while closing this stream.public void mark(int readlimit)
readlimit is ignored. Sending reset() will reposition the
stream back to the marked position.mark in class java.io.InputStreamreadlimit - ignored.markSupported(),
reset()public boolean markSupported()
mark() and
reset() methods. Returns true since this class supports
these methods.public int read()
read in class java.io.InputStreampublic 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 java.io.InputStreamb - the byte array in which to store the bytes read.offset - the initial position in b to store the bytes read from
this stream.length - the maximum number of bytes to store in b.java.lang.IndexOutOfBoundsException - if offset < 0 or length < 0, or if
offset + length is greater than the size of
b.java.lang.NullPointerException - if b is null.public void reset()
reset in class java.io.InputStreammark(int)public long skip(long n)
count number of bytes in this InputStream. Subsequent
read()s will not return these bytes unless reset() is
used. This implementation skips count number of bytes in the
target stream. It does nothing and returns 0 if n is negative.skip in class java.io.InputStreamn - the number of bytes to skip.Copyright © 2016 The Apache Software Foundation