List of usage examples for java.io ByteArrayOutputStream close
public void close() throws IOException
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(); baos.write(buf);//from w ww .ja v a 2s . c o m System.out.print(baos.toString()); }
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(); 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: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(); InputStream in = new ByteArrayInputStream(bOut.toByteArray()); CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC"); X509Certificate x509Cert;/*from w ww. j a va 2s. c o m*/ 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:geocodingsql.Main.java
/** * @param args the command line arguments *///from ww w.j a va 2 s . com public static void main(String[] args) throws JSONException { Main x = new Main(); ResultSet rs = null; String string = ""; x.establishConnection(); rs = x.giveName(); try { while (rs.next()) { string += rs.getString(1) + " "; } JOptionPane.showMessageDialog(null, string, "authors", 1); } catch (Exception e) { System.out.println("Problem when printing the database."); } x.closeConnection(); // Now do Geocoding String req = "https://maps.googleapis.com/maps/api/geocode/json?latlng=41.3166662867211,-72.9062497615814&result_type=point_of_interest&key=" + key; try { URL url = new URL(req + "&sensor=false"); URLConnection conn = url.openConnection(); ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copy(conn.getInputStream(), output); output.close(); req = output.toString(); } catch (Exception e) { System.out.println("Geocoding Error"); } JSONObject jObject = new JSONObject(req); JSONArray resultArray = jObject.getJSONArray("results"); //this prints out the neighborhood of the provided coordinates System.out.println(resultArray.getJSONObject(0).getJSONArray("address_components") .getJSONObject("neighborhood").getString("long_name")); }
From source file:Main.java
License:asdf
public static void main(String[] argv) throws Exception { byte[] input = "asdf".getBytes(); Deflater compressor = new Deflater(); compressor.setLevel(Deflater.BEST_COMPRESSION); compressor.setInput(input);//from w w w .java 2s . co m compressor.finish(); ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); byte[] buf = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buf); bos.write(buf, 0, count); } bos.close(); byte[] compressedData = bos.toByteArray(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] input = "www.java2s.com".getBytes(); Deflater compressor = new Deflater(); compressor.setLevel(Deflater.BEST_COMPRESSION); compressor.setInput(input);/*from www. j av a 2 s . com*/ compressor.finish(); ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); byte[] buf = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buf); bos.write(buf, 0, count); } bos.close(); byte[] compressedData = bos.toByteArray(); System.out.println(Arrays.toString(compressedData)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] compressedData = null; Inflater decompressor = new Inflater(); decompressor.setInput(compressedData); ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count);//from www .j a v a 2 s .c o m } bos.close(); byte[] decompressedData = bos.toByteArray(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ResultSet rset = null;/*from ww w . j a v a2s . 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:Main.java
public static void main(String[] argv) throws Exception { byte[] input = "this is a test".getBytes(); Deflater compressor = new Deflater(); compressor.setLevel(Deflater.BEST_COMPRESSION); compressor.setInput(input);//from w ww . j av a 2s. co m compressor.finish(); ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); byte[] buf = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buf); bos.write(buf, 0, count); } bos.close(); byte[] compressedData = bos.toByteArray(); Inflater decompressor = new Inflater(); decompressor.setInput(compressedData); bos = new ByteArrayOutputStream(compressedData.length); buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } bos.close(); byte[] decompressedData = bos.toByteArray(); System.out.println(new String(decompressedData)); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table images (Id int, b BLOB);"); File file = new File("myimage.gif"); FileInputStream fis = new FileInputStream(file); PreparedStatement ps = conn.prepareStatement("insert into images values (?,?)"); ps.setString(1, "10"); ps.setBinaryStream(2, fis);//from w w w . j a va 2 s.co m ps.executeUpdate(); ResultSet rset = st.executeQuery("select b from images"); 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(); ps.close(); fis.close(); st.close(); conn.close(); }