public class FastByteArrayInputStream extends InputStream
The idea for such an implementation was originally obtained from Berkeley DB JE, however, this represents a clean-room implementation that is NOT derived from their implementation for license reasons and differs in implementation considerably. For compatibility reasons we have tried to conserve the interface as much as possible.
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
The Buf.
|
protected int |
count
The Count.
|
protected int |
mark
The Mark.
|
protected int |
pos
The Pos.
|
protected int |
readlimit
The Readlimit.
|
| Constructor and Description |
|---|
FastByteArrayInputStream(byte[] buffer)
Creates a new FastByteArrayInputStream instance
that allows to read from the given byte array.
|
FastByteArrayInputStream(byte[] buffer,
int offset,
int length)
Creates a new FastByteArrayInputStream instance
that allows to read from the given byte array.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes that can be read (or skipped over) from this
FastByteArrayInputStream.
|
void |
close()
The close method for this FastByteArrayInputStream
does nothing.
|
byte[] |
getBuffer()
Returns the underlying data being read.
|
int |
getPosition()
Returns the offset at which data is being read from the buffer.
|
void |
mark(int limit)
Marks the current position in this FastByteArrayInputStream.
|
boolean |
markSupported()
Tests if this FastByteArrayInputStream
supports the mark and reset methods.
|
int |
read()
Reads the next byte of data from this input stream.
|
int |
read(byte[] toBuf) |
int |
read(byte[] toBuf,
int offset,
int length)
Reads up to len bytes of data into an array of bytes from this input stream.
|
void |
reset()
Re-positions this stream to the position at
the time the mark method was last called this FastByteArrayInputStream.
|
int |
size()
Returns the size of the buffer being read.
|
long |
skip(long n)
Skips over and discards n bytes of data from this input stream.
|
protected int count
protected int pos
protected int mark
protected byte[] buf
protected int readlimit
public FastByteArrayInputStream(byte[] buffer)
buffer - the data to be read.public FastByteArrayInputStream(byte[] buffer,
int offset,
int length)
buffer - the data to read.offset - the byte offset at which to begin reading.length - the number of bytes to read.public int read()
throws IOException
This read method cannot block.
read in class InputStreamIOException - errorpublic int read(byte[] toBuf,
int offset,
int length)
throws IOException
read in class InputStreamtoBuf - the buffer into which the data is read.offset - the start offset of the data.length - the max number of bytes read.IOException - errorpublic int read(byte[] toBuf)
throws IOException
read in class InputStreamIOExceptionpublic long skip(long n)
<=0
if none was skipped.
The maximum number of bytes that can be skipped is defined by Integer.MAX_VALUE.
skip in class InputStreamn - the number of bytes to be skipped.public void close()
close in interface Closeableclose in interface AutoCloseableclose in class InputStreampublic int available()
available in class InputStreampublic void mark(int limit)
reset() will re-postition this FastByteArrayInputStream
at the last marked position so that subsequent reads re-read the same bytes.mark in class InputStreamlimit - a read limit that invalidates the mark if passed.public boolean markSupported()
markSupported in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOException - if the readlimit was exceeded.public byte[] getBuffer()
public int getPosition()
public int size()
Copyright © 2017. All rights reserved.