public class FastByteArrayInputStream extends MeasurableInputStream implements RepositionableStream
Warning: this class implements the correct semantics
of read(byte[], int, int)
as described in InputStream
.
The implementation given in ByteArrayInputStream
is broken,
but it will never be fixed because it's too late.
Modifier and Type | Field and Description |
---|---|
byte[] |
array
The array backing the input stream.
|
int |
length
|
int |
offset
The first valid entry.
|
Constructor and Description |
---|
FastByteArrayInputStream(byte[] array)
Creates a new array input stream using a given array.
|
FastByteArrayInputStream(byte[] array,
int offset,
int length)
Creates a new array input stream using a given array fragment.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close()
Closing a fast byte array input stream has no effect.
|
long |
length()
Returns the overall length of this stream (optional operation).
|
void |
mark(int dummy) |
boolean |
markSupported() |
long |
position()
Returns the current stream position.
|
void |
position(long newPosition)
Sets the current stream position.
|
int |
read() |
int |
read(byte[] b,
int offset,
int length)
Reads bytes from this byte-array input stream as
specified in
InputStream.read(byte[], int, int) . |
void |
reset() |
long |
skip(long n) |
read
public byte[] array
public int offset
public int length
public FastByteArrayInputStream(byte[] array, int offset, int length)
array
- the backing array.offset
- the first valid entry of the array.length
- the number of valid bytes.public FastByteArrayInputStream(byte[] array)
array
- the backing array.public boolean markSupported()
markSupported
in class InputStream
public void reset()
reset
in class InputStream
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
public void mark(int dummy)
mark
in class InputStream
public int available()
available
in class InputStream
public long skip(long n)
skip
in class InputStream
public int read()
read
in class InputStream
public int read(byte[] b, int offset, int length)
InputStream.read(byte[], int, int)
.
Note that the implementation given in ByteArrayInputStream.read(byte[], int, int)
will return -1 on a zero-length read at EOF, contrarily to the specification. We won't.read
in class InputStream
public long position()
RepositionableStream
position
in interface MeasurableStream
position
in interface RepositionableStream
public void position(long newPosition)
RepositionableStream
position
in interface RepositionableStream
newPosition
- the new stream position.public long length()
MeasurableStream
length
in interface MeasurableStream