Skip to content

Most visited

Recently visited

navigation
Added in API level 1

ByteArrayInputStream

public class ByteArrayInputStream
extends InputStream

java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.ByteArrayInputStream


A specialized InputStream for reading the contents of a byte array.

See also:

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

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.

Public methods

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.

Inherited methods

From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Fields

buf

Added in API level 1
byte[] buf

The byte array containing the bytes to stream over.

count

Added in API level 1
int count

The total number of bytes initially available in the byte array buf.

mark

Added in API level 1
int mark

The current mark position. Initially set to 0 or the offset parameter within the constructor.

pos

Added in API level 1
int pos

The current position within the byte array.

Public constructors

ByteArrayInputStream

Added in API level 1
ByteArrayInputStream (byte[] buf)

Constructs a new ByteArrayInputStream on the byte array buf.

Parameters
buf byte: the byte array to stream over.

ByteArrayInputStream

Added in API level 1
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.

Parameters
buf byte: the byte array to stream over.
offset int: the initial position in buf to start streaming from.
length int: the number of bytes available for streaming.

Public methods

available

Added in API level 1
int available ()

Returns the number of remaining bytes.

Returns
int count - pos

close

Added in API level 1
void close ()

Closes this stream and frees resources associated with this stream.

Throws
IOException if an I/O error occurs while closing this stream.

mark

Added in API level 1
void mark (int readlimit)

Sets a mark position in this ByteArrayInputStream. The parameter readlimit is ignored. Sending reset() will reposition the stream back to the marked position.

Parameters
readlimit int: ignored.

See also:

markSupported

Added in API level 1
boolean markSupported ()

Indicates whether this stream supports the mark() and reset() methods. Returns true since this class supports these methods.

Returns
boolean always true.

See also:

read

Added in API level 1
int read ()

Reads a single byte from the source byte array and returns it as an integer in the range from 0 to 255. Returns -1 if the end of the source array has been reached.

Returns
int the byte read or -1 if the end of this stream has been reached.

read

Added in API level 1
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. Returns the number of bytes actually read or -1 if the end of the stream has been reached.

Parameters
buffer byte
byteOffset int
byteCount int
Returns
int

reset

Added in API level 1
void reset ()

Resets this stream 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 has been provided.

See also:

skip

Added in API level 1
long skip (long byteCount)

Skips 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.

Parameters
byteCount long
Returns
long the number of bytes actually skipped.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.