Java ByteArrayInputStream Class

The ByteArrayInputStream is composed of two words: ByteArray and InputStream. As the name suggests, it can be used to read byte array as input stream.

Java ByteArrayInputStream class contains an internal buffer which is used to read byte array as stream. In this stream, the data is read from a byte array.

The buffer of ByteArrayInputStream automatically grows according to data.

Java ByteArrayInputStream class declaration

public class ByteArrayInputStream extends InputStream

Java ByteArrayInputStream class constructors

Method Description
ByteArrayInputStream() Creates a new byte array input stream which uses ary as its buffer array.
ByteArrayInputStream(byte[] ary, int offset, int len) Creates a new byte array input stream which uses ary as its buffer array that can read up to specified len bytes of data from an array.

Java ByteArrayInputStream class methods

Method Description
int available() It is used to return the number of remaining bytes that can be read from the input stream.
int read() It is used to read the next byte of data from the input stream.
int read(byte[] ary, int off, int len) It is used to read up to len bytes of data from an array of bytes in the input stream.
boolean markSupported() It is used to test the input stream for mark and reset method.
long skip(long x) It is used to skip the x bytes of input from the input stream.
void mark(int readAheadLimit) It is used to set the current marked position in the stream.
void reset() It is used to reset the buffer of a byte array.

Example of Java ByteArrayInputStream

Flash Soon


Output:



Advertisement

Copyright ©2017 Design& develop