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) |
readpublic 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 InputStreampublic void reset()
reset in class InputStreampublic void close()
close in interface Closeableclose in interface AutoCloseableclose in class InputStreampublic void mark(int dummy)
mark in class InputStreampublic int available()
available in class InputStreampublic long skip(long n)
skip in class InputStreampublic int read()
read in class InputStreampublic 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 InputStreampublic long position()
RepositionableStreamposition in interface MeasurableStreamposition in interface RepositionableStreampublic void position(long newPosition)
RepositionableStreamposition in interface RepositionableStreamnewPosition - the new stream position.public long length()
MeasurableStreamlength in interface MeasurableStreamCopyright © 2020. All rights reserved.