List of usage examples for java.io ByteArrayOutputStream toByteArray
public synchronized byte[] toByteArray()
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);//from w w w. ja v a2s .c o 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:MainClass.java
public static void main(String args[]) throws Exception { String[] a = new String[] { "a", "b", "c" }; Vector v = new Vector(Arrays.asList()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(v);/* w ww . j a v a 2s. com*/ 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 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 a va 2 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 { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); byte[] bytes = { 1, 2, 3, 4, 5 }; bos.write(bytes, 0, 5);/*from w ww . j a v a 2s .c o m*/ bos.flush(); for (byte b : baos.toByteArray()) { System.out.print(b); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException, ClassNotFoundException { MyBean sc = new MyBean("Test1", "Test2"); System.out.println("Before:\n" + sc); ByteArrayOutputStream buf = new ByteArrayOutputStream(); ObjectOutputStream o = new ObjectOutputStream(buf); o.writeObject(sc);/* w w w . ja va 2 s .c o m*/ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray())); MyBean sc2 = (MyBean) in.readObject(); System.out.println("After:\n" + sc2); }
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 v a 2s.c om } dos.flush(); for (byte b : baos.toByteArray()) { System.out.print(b); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyPair pair = generateRSAKeyPair(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); bOut.write(generateV1Certificate(pair).getEncoded()); bOut.close();/*from ww w . j a v a 2s . c o m*/ InputStream in = new ByteArrayInputStream(bOut.toByteArray()); CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC"); X509Certificate x509Cert; Collection collection = new ArrayList(); while ((x509Cert = (X509Certificate) fact.generateCertificate(in)) != null) { collection.add(x509Cert); } Iterator it = collection.iterator(); while (it.hasNext()) { System.out.println("version: " + ((X509Certificate) it.next()).getVersion()); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new BouncyCastleProvider()); byte[] input = "www.java2s.com".getBytes(); System.out.println("input : " + new String(input)); MessageDigest hash = MessageDigest.getInstance("SHA1"); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input); DigestInputStream digestInputStream = new DigestInputStream(byteArrayInputStream, hash); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int ch;/*w w w. j a v a2 s . com*/ while ((ch = digestInputStream.read()) >= 0) { byteArrayOutputStream.write(ch); } byte[] newInput = byteArrayOutputStream.toByteArray(); System.out.println("in digest : " + new String(digestInputStream.getMessageDigest().digest())); byteArrayOutputStream = new ByteArrayOutputStream(); DigestOutputStream digestOutputStream = new DigestOutputStream(byteArrayOutputStream, hash); digestOutputStream.write(newInput); digestOutputStream.close(); System.out.println("out digest: " + new String(digestOutputStream.getMessageDigest().digest())); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ResultSet rset = null;//w w w . j a v a 2s.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:net.sf.jabb.util.text.test.KeywordMatcherExample.java
/** * @param args// www . j a v a 2 s .co m * @throws IOException * @throws ClassNotFoundException */ public static void main(String[] args) throws IOException, ClassNotFoundException { System.out.println("==== ===="); KeywordMatcher m = showExample(null); System.out.println("==== ? ===="); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(m); byte[] binary = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(binary); ObjectInputStream ois = new ObjectInputStream(bais); KeywordMatcher m2 = (KeywordMatcher) ois.readObject(); showExample(m2); System.out.println("==== ? ===="); KeywordMatcher m3 = new KeywordMatcher(m); showExample(m3); }