List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
public static void main(String[] args) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // write byte array to the output stream baos.write(55);//from w w w .jav a 2 s . c om // converts the byte to the default charset value String str = baos.toString(); // prints the string System.out.println(str); }
From source file:Main.java
public static void main(String[] args) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(75);/* w w w . j a v a2 s . c om*/ String str = baos.toString(); System.out.println("Before Resetting : " + str); baos.reset(); baos.write(65); str = baos.toString(); System.out.println("After Resetting : " + str); }
From source file:Main.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); byte[] bytes = { 1, 2, 3, 4, 5 }; bos.write(bytes, 0, 5);//from w w w. ja v a2 s .c o m bos.flush(); for (byte b : baos.toByteArray()) { System.out.print(b); } }
From source file:Main.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); int b = 87;/*w ww . j av a 2s .co m*/ bos.write(b); bos.flush(); byte[] bytes = baos.toByteArray(); System.out.println(bytes[0]); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = { 65, 66, 67, 68, 69 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(bs);/*from w w w .j a v a 2 s . c om*/ String str = baos.toString(); System.out.println(str); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = { 65, 66, 67, 68, 69 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); // write byte array to the output stream baos.write(bs, 3, 2);//from w w w . j ava 2 s .c o m // read all the bytes in the output stream for (byte b : baos.toByteArray()) { System.out.println(b); } }
From source file:Main.java
public static void main(String args[]) throws IOException { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i));/* w w w .j a v a 2 s. c om*/ System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); int inBytes = inStream.available(); System.out.println("inStream has " + inBytes + " available bytes"); byte inBuf[] = new byte[inBytes]; int bytesRead = inStream.read(inBuf, 0, inBytes); System.out.println(bytesRead + " bytes were read"); System.out.println("They are: " + new String(inBuf)); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.close();/*from w w w. j a v a2 s. c o m*/ baos.write(buf); System.out.print(baos.toString()); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = { 65, 66, 67, 68, 69 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(bs);/*ww w . j a v a2 s. c o m*/ for (byte b : baos.toByteArray()) { baos.write(b); System.out.println(b); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = { 65, 66, 67, 68, 69 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(bs);//from ww w. j av a 2 s . c o m // converts buffers content using Cp1047 character set String str = baos.toString("Cp1047"); System.out.println(str); // converts buffers contents using UTF-8 character set str = baos.toString("UTF-8"); System.out.println(str); }