Java - Bytearrayinputstream: SN Methods With Desc Ription Public Int Read
Java - Bytearrayinputstream: SN Methods With Desc Ription Public Int Read
http://www.tuto rialspo int.co m/java/java_byte arrayinputstre am.htm Co pyrig ht © tuto rials po int.co m
T he ByteArrayInputStream class allows a buffer in the memory to be used as an InputStream. T he input source is
a byte array. T here are following forms of constructors to create ByteArrayInputStream objects
Another form takes an array of bytes, and two ints, where off is the first byte to be read and len is the number of
bytes to be read.
Once you have ByteArrayInputStream object in hand then there is a list of helper methods which can be used to
read the stream or to do other operations on the stream.
Example:
Following is the example to demonstrate ByteArrayInputStream and ByteArrayOutputStream
import java.io.*;
while( bOutput.size()!= 10 ) {
// Gets the inputs from the user
bOutput.write(System.in.read());
}
byte b [] = bOutput.toByteArray();
System.out.println("Print the content");
for(int x= 0 ; x < b.length; x++) {
// printing the characters
System.out.print((char)b[x] + " ");
}
System.out.println(" ");
int c;
asdfghjkly
Print the content
a s d f g h j k l y
Converting characters to Upper case
A
S
D
F
G
H
J
K
L
Y