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 { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyPair pair = generateRSAKeyPair(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); bOut.write(generateV1Certificate(pair).getEncoded()); bOut.close();//from w w w . j a v a 2s.c om InputStream in = new ByteArrayInputStream(bOut.toByteArray()); CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC"); X509Certificate x509Cert = (X509Certificate) fact.generateCertificate(in); System.out.println("issuer: " + x509Cert.getIssuerX500Principal()); }
From source file:SaveVector.java
public static void main(String args[]) throws Exception { String data[] = { "Java", "Source", "and", "Support", "." }; Vector v = new Vector(Arrays.asList(data)); ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutputStream o = new ObjectOutputStream(b); o.writeObject(v);/*from ww w. j a v a 2s . c o m*/ o.close(); ByteArrayInputStream bb = new ByteArrayInputStream(b.toByteArray()); ObjectInputStream oo = new ObjectInputStream(bb); Vector v2 = (Vector) oo.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 { String os = "abc"; for (byte b : os.getBytes("UTF-16BE")) { System.out.println(b);// w w w. j a v a2s . c o 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:net.awl.edoc.pdfa.font.CFFTest.java
/** * @param args/* ww w . ja v a2s. co m*/ */ public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("/home/eric/UneCFFType0.cff0"); // FileInputStream fis = new FileInputStream("/home/eric/UneCFFType2.cff2"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copyLarge(fis, bos); CFFParser cp = new CFFParser(); List<CFFFont> lf = cp.parse(bos.toByteArray()); CFFFontROS font = (CFFFontROS) lf.get(0); System.out.println("CharstringType : " + font.getProperty("CharstringType")); int CID = 85; int fdAIndex = font.getFdSelect().getFd(CID); Map<String, Object> fd = font.getFontDict().get(fdAIndex); Map<String, Object> pd = font.getPrivDict().get(fdAIndex); for (Mapping m : font.getMappings()) { if (m.getSID() == CID) { // List<Object> l1 = new // Type1CharStringParser().parse(font.getCharStringsDict().get(m.getName())); List<Object> l2 = new Type2CharStringParser().parse(m.getBytes()); System.err.println(""); } } System.out.println(""); }
From source file:Main.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String URL = "jdbc:odbc:dbname"; Connection dbConn = DriverManager.getConnection(URL, "user", "passw"); Employee employee = new Employee(42, "AA", 9); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(employee);/*w w w. j a v a2 s . c o m*/ byte[] employeeAsBytes = baos.toByteArray(); PreparedStatement pstmt = dbConn.prepareStatement("INSERT INTO EMPLOYEE (emp) VALUES(?)"); ByteArrayInputStream bais = new ByteArrayInputStream(employeeAsBytes); pstmt.setBinaryStream(1, bais, employeeAsBytes.length); pstmt.executeUpdate(); pstmt.close(); Statement stmt = dbConn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT emp FROM Employee"); while (rs.next()) { byte[] st = (byte[]) rs.getObject(1); ByteArrayInputStream baip = new ByteArrayInputStream(st); ObjectInputStream ois = new ObjectInputStream(baip); Employee emp = (Employee) ois.readObject(); } stmt.close(); rs.close(); dbConn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Object object = new JButton("push me"); ObjectOutput out = new ObjectOutputStream(new FileOutputStream("filename.ser")); out.writeObject(object);/* ww w .j a va 2 s. co m*/ out.close(); // Serialize to a byte array ByteArrayOutputStream bos = new ByteArrayOutputStream(); out = new ObjectOutputStream(bos); out.writeObject(object); out.close(); // Get the bytes of the serialized object byte[] buf = bos.toByteArray(); System.out.println(new String(buf)); }
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);// w ww. j a va 2s . 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: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 av a 2 s. c o m } 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 IOException { String s = "Hello from java2s.com!"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeBytes(s);/* www . jav a2s. c om*/ dos.flush(); System.out.println(s + " in bytes:"); 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()); byte[] input = "www.java2s.com".getBytes(); byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }; byte[] ivBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };/*from www . ja v a 2 s . c om*/ SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); IvParameterSpec ivSpec = new IvParameterSpec(ivBytes); Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding", "BC"); System.out.println("input : " + new String(input)); // encryption pass cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); ByteArrayInputStream bIn = new ByteArrayInputStream(input); CipherInputStream cIn = new CipherInputStream(bIn, cipher); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); int ch; while ((ch = cIn.read()) >= 0) { bOut.write(ch); } byte[] cipherText = bOut.toByteArray(); System.out.println("cipher: " + new String(cipherText)); // decryption pass cipher.init(Cipher.DECRYPT_MODE, key, ivSpec); bOut = new ByteArrayOutputStream(); CipherOutputStream cOut = new CipherOutputStream(bOut, cipher); cOut.write(cipherText); cOut.close(); System.out.println("plain : " + new String(bOut.toByteArray())); }