List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
public static void main(String[] args) throws IOException { boolean[] bools = { true, false, false, true, true, true }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (boolean bool : bools) { dos.writeBoolean(bool);/*from w ww . j a va2 s.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 Exception { FileInputStream is = new FileInputStream("c:/test.txt"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos, 200); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream is = new FileInputStream("c:/test.txt"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); }
From source file:Main.java
public static void main(String[] args) throws Exception { String os = "abc"; for (byte b : os.getBytes("UTF-16BE")) { System.out.println(b);//from w w w. j av a 2 s . co m } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (char c : os.toCharArray()) { dos.writeChar(c); } byte[] ba = baos.toByteArray(); for (byte b : ba) { System.out.println(b); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Path sourceFile = FileSystems.getDefault().getPath("C:/home/docs/users.txt"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Files.copy(sourceFile, outputStream); byte arr[] = outputStream.toByteArray(); System.out.println("The contents of " + sourceFile.getFileName()); for (byte data : arr) { System.out.print((char) data); }//from w w w .j a va2s. co m }
From source file:Main.java
public static void main(String[] argv) throws Exception { ResultSet rset = null;/*from w w w .jav a2 s . co m*/ InputStream stream = rset.getBinaryStream(1); ByteArrayOutputStream output = new ByteArrayOutputStream(); int a1 = stream.read(); while (a1 >= 0) { output.write((char) a1); a1 = stream.read(); } Image myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray()); output.close(); }
From source file:SaveVector1.java
public static void main(String args[]) throws Exception { Vector v = new Vector(Arrays.asList(args)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(v);/* ww w. ja v a2 s . c om*/ oos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); Vector v2 = (Vector) ois.readObject(); Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { Vector v = new Vector(Arrays.asList("a", "b", "c")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(v);/* w w w . j av a 2 s .co m*/ oos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); Vector v2 = (Vector) ois.readObject(); Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream is = new FileInputStream("c:/test.txt"); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); int value;//from ww w . ja v a 2 s. c o m while ((value = bis.read()) != -1) { bos.write(value); } bos.flush(); for (byte b : baos.toByteArray()) { char c = (char) b; System.out.println(c); } }
From source file:Main.java
public static void main(String[] arg) throws Throwable { File f = new File(arg[0]); InputStream in = new FileInputStream(f); byte[] buff = new byte[8000]; int bytesRead = 0; ByteArrayOutputStream bao = new ByteArrayOutputStream(); while ((bytesRead = in.read(buff)) != -1) { bao.write(buff, 0, bytesRead);// w ww .jav a 2 s .co m } in.close(); byte[] data = bao.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(data); System.out.println(bin.available()); }