public class UnsyncByteArrayInputStream extends InputStream
InputStream
for reading the contents of a byte array.UnsyncByteArrayOutputStream
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 |
---|
UnsyncByteArrayInputStream(byte[] buf)
Constructs a new
ByteArrayInputStream on the byte array
buf . |
UnsyncByteArrayInputStream(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. |
read
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 UnsyncByteArrayInputStream(byte[] buf)
ByteArrayInputStream
on the byte array
buf
.buf
- the byte array to stream over.public UnsyncByteArrayInputStream(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 InputStream
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
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 InputStream
readlimit
- ignored.markSupported()
,
reset()
public boolean markSupported()
mark()
and
reset()
methods. Returns true
since this class supports
these methods.markSupported
in class InputStream
true
.mark(int)
,
reset()
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 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
.IndexOutOfBoundsException
- if offset < 0
or length < 0
, or if
offset + length
is greater than the size of
b
.NullPointerException
- if b
is null
.public void reset()
reset
in class InputStream
mark(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 InputStream
n
- the number of bytes to skip.Copyright © 2000–2020 The Apache Software Foundation. All rights reserved.