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 outStream = new ByteArrayOutputStream(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i));/*from w w w . ja v a 2s .c om*/ System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); ByteArrayInputStream inStream; 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:ByteArrayIOApp.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 ww .ja v a 2s. c om System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); ByteArrayInputStream inStream; 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[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 }; OutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(bs);//from ww w .ja v a 2s. c o m baos.writeTo(os); System.out.println(os.toString()); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 }; OutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(200); baos.write(bs);// w w w.j a v a 2 s. c o m baos.writeTo(os); System.out.println(os.toString()); }
From source file:Main.java
public static void main(String[] args) throws IOException { int size = 0; byte[] bs = { 65, 66, 67, 68, 69 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (byte b : bs) { baos.write(b);/*from ww w . j ava2 s . c o m*/ String str = baos.toString(); size = baos.size(); System.out.print(size + ":"); System.out.println(str); } }
From source file:Main.java
public static void main(String[] args) throws IOException { String s = "Hello from java2s.com!"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeBytes(s);// w w w. j a va 2 s . co m dos.flush(); System.out.println(s + " in bytes:"); for (byte b : baos.toByteArray()) { System.out.print(b + ","); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 87, 64, 72, 31, 90 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.write(buf, 2, 3);//from w w w . jav a 2 s.co m dos.flush(); for (byte b : baos.toByteArray()) { System.out.println(b); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 12, 15, 18, 20, 22, 24 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (byte b : buf) { dos.writeByte(b);//from w ww . j av a2s. c o m } dos.flush(); for (byte b : baos.toByteArray()) { System.out.print(b); } }
From source file:Main.java
public static void main(String[] args) throws IOException { int[] buf = { 65, 66, 67, 68, 69, 70, 71 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (int i : buf) { dos.write(i);//from w w w.j a v a 2s . c om } dos.flush(); for (byte b : baos.toByteArray()) { char c = (char) b; System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); MessageDigest md = MessageDigest.getInstance("MD5"); SomeObject testObject = new SomeObject(); dos.writeInt(testObject.count);/*from w ww . jav a 2s.c o m*/ dos.writeLong(testObject.product); dos.writeDouble(testObject.stdDev); dos.writeUTF(testObject.name); dos.writeChar(testObject.delimiter); dos.flush(); byte[] hashBytes = md.digest(baos.toByteArray()); BigInteger testObjectHash = new BigInteger(hashBytes); System.out.println("Hash " + testObjectHash); dos.close(); }