import java.io.ByteArrayOutputStream;
import java.io.IOException;
// The ByteArrayOutputStream class stream creates a buffer in memory and all the data sent to
// the stream is stored in the buffer.Following constructor creates a buffer of 32 byte:
//OutputStream bOut = new ByteArrayOutputStream()
//OutputStream bOut = new ByteArrayOutputStream(int a)
//Methods
//public void reset()
//public byte[] toByteArray()
//public String toString()
//public void write(int w)
//public void write(byte []b, int of, int len)
//public void writeTo(OutputStream outSt)
public class ByteArrayOutputStreamDemo {
public static void main(String[] args) throws IOException {
System.out.println("Please enter contents: ");
ByteArrayOutputStream bOut = new ByteArrayOutputStream(12);
while(bOut.size() != 10){
bOut.write(System.in.read());
}
byte[] b = bOut.toByteArray();
System.out.println("Print the user entered contents");
for (int i = 0; i < b.length; i++) {
System.out.print((char)b[i] + " ");
}
System.out.println(" ");
int c;
ByteArrayInputStream bIn = new ByteArrayInputStream(b);
System.out.println("Converting All the characters to the upper case");
for (int i = 0; i < 1; i++) {
while((c = bIn.read()) != -1){
System.out.println(Character.toUpperCase((char)c));
}
}
}
}

No comments:
Post a Comment