ByteArrayInputStream class

 

                  See  InputStream class  for descriptions of ByteArrayInputStream’s inherited methods.  They are:

 

available( )                   Tells how many bytes can be gotten without blocking.

close( )                         Close the stream.

mark( int readAheadLimit )  Mark the present position in the stream.

markSupported( )         Tell whether this stream supports the mark(...) operation.

read( )                          Read a single byte, returning it as the low end of an int.

read( byte[ ] b )             Read bytes into a byte array.

read( byte[ ] b, int off, int len)  Read bytes into a portion of a byte array.

ready( )                         Tell whether this stream is ready to be read.

reset( )                          Reset the stream to the beginning.

skip( long n )                Skip characters.

 

 

  See CharArrayReader class.     ByteArrayInputStream reads from a byte array the same way that  CharArrayReader  reads from a char array.  Its methods and constructors work the same. 

 

 Neither its constructors or its read( ) methods throw any IOExceptions.

 

 This example using .read( )  returns either the next byte from the array, in an int, or -1 in that int to indicate EOF.  i.e.

 

import java.io.*;

 

byte[ ] b = { 0,1,2,3,4,5,6,7,8,9} ;

ByteArrayInputStream bais = new ByteArrayInputStream( b );    // constructor indicates array to be read from

int x;

   while ( (x = bais.read( ) ) != -1 ) {

       System.out.print( x );

    }