public class ByteArrayInputStream extends InputStream
InputStream
for reading the contents of a byte array.ByteArrayOutputStream
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 |
---|
ByteArrayInputStream(byte[] buf)
Constructs a new
ByteArrayInputStream on the byte array
buf . |
ByteArrayInputStream(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 remaining bytes.
|
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[] buffer,
int byteOffset,
int byteCount)
Reads up to
byteCount bytes from this stream and stores them in
the byte array buffer starting at byteOffset . |
void |
reset()
Resets this stream to the last marked location.
|
long |
skip(long byteCount)
Skips
byteCount 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 ByteArrayInputStream(byte[] buf)
ByteArrayInputStream
on the byte array
buf
.buf
- the byte array to stream over.public ByteArrayInputStream(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
count - pos
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[] buffer, int byteOffset, int byteCount)
InputStream
byteCount
bytes from this stream and stores them in
the byte array buffer
starting at byteOffset
.
Returns the number of bytes actually read or -1 if the end of the stream
has been reached.read
in class InputStream
public void reset()
reset
in class InputStream
mark(int)
public long skip(long byteCount)
byteCount
bytes in this InputStream. Subsequent
calls to read
will not return these bytes unless reset
is
used. This implementation skips byteCount
number of bytes in the
target stream. It does nothing and returns 0 if byteCount
is negative.skip
in class InputStream
Copyright © 2018. All rights reserved.