List of usage examples for java.io ByteArrayOutputStream close
public void close() throws IOException
From source file:co.rsk.peg.BridgeSerializationUtils.java
public static byte[] serializeList(List<UTXO> list) throws IOException { int nutxos = list.size(); byte[][] bytes = new byte[nutxos][]; int n = 0;//from ww w . j a v a2 s. c om for (UTXO utxo : list) { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); utxo.serializeToStream(ostream); ostream.close(); bytes[n++] = RLP.encodeElement(ostream.toByteArray()); } return RLP.encodeList(bytes); }
From source file:Main.java
public static byte[] InputStreamTOByteArray(InputStream in) throws IOException { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); int count = -1; byte[] data = new byte[BUFFER_SIZE]; while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) { outStream.write(data, 0, count); }/*from w w w .j a va 2 s. c o m*/ data = null; outStream.close(); return outStream.toByteArray(); }
From source file:Main.java
public static byte[] inputStreamToByte(InputStream is) { try {//from w ww . j a v a2s . c o m ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); int ch; while ((ch = is.read()) != -1) { bytestream.write(ch); } byte imgdata[] = bytestream.toByteArray(); bytestream.close(); return imgdata; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.eucalyptus.auth.crypto.StringCryptoTest.java
private static byte[] readfile(String filename) throws Exception { FileInputStream fis = new FileInputStream(filename); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] block = new byte[512]; int n;//from w ww. j a v a2 s.c o m while ((n = fis.read(block)) > 0) { baos.write(block, 0, n); } byte[] bytes = baos.toByteArray(); baos.close(); return bytes; }
From source file:Main.java
public static String uncompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data);//ww w .jav a2 s . com ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); // Decode the bytes into a String return new String(output, 0, output.length, "UTF-8"); }
From source file:Main.java
public static String readInputStream(InputStream is) { try {// www . j av a2 s . co m ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] buffer = new byte[1024]; while ((len = is.read(buffer)) != -1) { baos.write(buffer, 0, len); } is.close(); baos.close(); byte[] result = baos.toByteArray(); String temp = new String(result); return temp; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data);/*from ww w .j a va 2 s. co m*/ inflater.finished(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); inflater.end(); return output; }
From source file:Main.java
public static String readData(InputStream inSream, String charsetName) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = inSream.read(buffer)) != -1) { outStream.write(buffer, 0, len); }/* w w w . j a va 2s . c o m*/ byte[] data = outStream.toByteArray(); outStream.close(); inSream.close(); return new String(data, charsetName); }
From source file:Main.java
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data);//from w ww .j a v a 2 s . c om ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); /* LOG.debug("Original: " + data.length); LOG.debug("Compressed: " + output.length); */ return output; }
From source file:Main.java
public static byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data);/*from w w w. j a va 2s .c o m*/ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); System.out.println("Original: " + data.length); System.out.println("Compressed: " + output.length); return output; }