public class ByteArrayInputStream extends InputStream
ByteArrayInputStreamcontains an internal buffer that contains bytes that may be read from the stream. An internal counter keeps track of the next byte to be supplied by the
Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
|Modifier and Type||Field and Description|
An array of bytes that was provided by the creator of the stream.
The index one greater than the last valid character in the input stream buffer.
The currently marked position in the stream.
The index of the next character to read from the input stream buffer.
|Constructor and Description|
|Modifier and Type||Method and Description|
Returns the number of remaining bytes that can be read (or skipped over) from this input stream.
Closing a ByteArrayInputStream has no effect.
Set the current marked position in the stream.
Tests if this
Reads the next byte of data from this input stream.
Reads up to
Resets the buffer to the marked position.
protected byte buf
buf[count-1]are the only bytes that can ever be read from the stream; element
buf[pos]is the next byte to be read.
protected int pos
count. The next byte to be read from the input stream buffer will be
protected int mark
mark()method. The current buffer position is set to this point by the
If no mark has been set, then the value of mark is the offset passed to the constructor (or 0 if the offset was not supplied).
protected int count
buf. It is one greater than the position of the last byte within
bufthat can ever be read from the input stream buffer.
public ByteArrayInputStream(byte buf)
ByteArrayInputStreamso that it uses
bufas its buffer array. The buffer array is not copied. The initial value of
0and the initial value of
countis the length of
buf- the input buffer.
public ByteArrayInputStream(byte buf, int offset, int length)
bufas its buffer array. The initial value of
offsetand the initial value of
countis the minimum of
buf.length. The buffer array is not copied. The buffer's mark is set to the specified offset.
buf- the input buffer.
offset- the offset in the buffer of the first byte to read.
length- the maximum number of bytes to read from the buffer.
public int read()
intin the range
255. If no byte is available because the end of the stream has been reached, the value
public int read(byte b, int off, int len)
lenbytes of data into an array of bytes from this input stream. If
-1is returned to indicate end of file. Otherwise, the number
kof bytes read is equal to the smaller of
kis positive, then bytes
buf[pos+k-1]are copied into
b[off+k-1]in the manner performed by
System.arraycopy. The value
kis added into
read method cannot block.
b- the buffer into which the data is read.
off- the start offset in the destination array
len- the maximum number of bytes read.
-1if there is no more data because the end of the stream has been reached.
lenis negative, or
lenis greater than
b.length - off
public long skip(long n)
nbytes of input from this input stream. Fewer bytes might be skipped if the end of the input stream is reached. The actual number
kof bytes to be skipped is equal to the smaller of
count-pos. The value
kis added into
public int available()
The value returned is
count - pos,
which is the number of bytes remaining to be read from the input buffer.
public boolean markSupported()
InputStreamsupports mark/reset. The
public void mark(int readAheadLimit)
If no mark has been set, then the value of the mark is the offset passed to the constructor (or 0 if the offset was not supplied).
readAheadLimit for this class
has no meaning.
public void reset()
public void close() throws IOException
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.