java.io.ByteArrayInputStream
ByteArrayInputStream is used for streaming over a byte array.
Summary
Fields
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. |
Public Constructors
Public Methods
|
synchronized |
|
|
|
int |
available() |
|
|
|
|
|
void |
close() |
|
synchronized |
|
|
|
void |
mark(int readlimit) |
|
|
|
|
|
boolean |
markSupported() |
|
synchronized |
|
|
|
int |
read(byte[] b, int offset, int length) |
|
synchronized |
|
|
|
int |
read() |
|
synchronized |
|
|
|
void |
reset() |
|
synchronized |
|
|
|
long |
skip(long n) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Fields
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. Initially set to 0 or the offset
parameter within the constructor.
protected
int
pos
The current position within the byte array.
Public Constructors
public
ByteArrayInputStream(byte[] buf)
Constructs a new ByteArrayInputStream on the byte array
buf
.
Parameters
buf
| the byte array to stream over
|
public
ByteArrayInputStream(byte[] buf, int offset, int length)
Constructs a new ByteArrayInputStream on the byte array
buf
with the position set to
offset
and the number of bytes
available set to
offset
+
length
.
Parameters
buf
| the byte array to stream over |
offset
| the offset in buf to start streaming at |
length
| the number of bytes available to stream over.
|
Public Methods
public
synchronized
int
available()
Returns a int representing then number of bytes that are available before
this ByteArrayInputStream will block. This method returns the number of
bytes yet to be read from the underlying byte array.
Returns
- the number of bytes available before blocking.
public
void
close()
Close the ByteArrayInputStream. This implementation frees up resources
associated with this stream.
Throws
IOException
| If an error occurs attempting to close this InputStream.
|
public
synchronized
void
mark(int readlimit)
Set a Mark position in this ByteArrayInputStream. The parameter
readLimit
is ignored. Sending reset() will reposition the
stream back to the marked position.
public
boolean
markSupported()
Returns a boolean indicating whether or not this ByteArrayInputStream
supports mark() and reset(). This implementation returns
true
.
Returns
true
indicates this stream supports mark/reset,
false
otherwise.
public
synchronized
int
read(byte[] b, int offset, int length)
Reads at most
len
bytes from this ByteArrayInputStream and
stores them in byte array
b
starting at offset
off
. Answer the number of bytes actually read or -1 if no
bytes were read and end of stream was encountered. This implementation
reads bytes from the target byte array.
Parameters
b
| the byte array in which to store the read bytes. |
offset
| the offset in b to store the read bytes. |
length
| the maximum number of bytes to store in b . |
Returns
- the number of bytes actually read or -1 if end of stream.
public
synchronized
int
read()
Reads a single byte from this ByteArrayInputStream and returns the result
as an int. The low-order byte is returned or -1 of the end of stream was
encountered. This implementation returns the next available byte from the
target byte array.
Returns
- the byte read or -1 if end of stream.
public
synchronized
void
reset()
Reset this ByteArrayInputStream to the last marked location. This
implementation resets the position to either the marked position, the
start position supplied in the constructor or 0
if neither
is provided.
public
synchronized
long
skip(long n)
Skips
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.
Parameters
n
| the number of bytes to skip. |
Returns
- the number of bytes actually skipped.