List of usage examples for java.io ByteArrayOutputStream write
public synchronized void write(int b)
From source file:Main.java
public static byte[] readBytes(InputStream is) throws IOException { try {// w w w.ja v a2 s .c o m BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int ch; while ((ch = bis.read()) >= 0) { bos.write(ch); } bos.flush(); return bos.toByteArray(); } finally { is.close(); } }
From source file:com.taobao.adfs.database.tdhsocket.client.protocol.TDHSProtocolBinary.java
private static void writeInt8ToStream(int v, ByteArrayOutputStream out) { out.write((byte) (v & 0XFF)); }
From source file:ByteUtils.java
public static byte[] encryptRaw(byte[] key, byte[] b) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (int i = 0; i < b.length; i++) { baos.write(b[i] ^ key[i % key.length]); }/*from w w w .j av a 2 s. co m*/ // baos.close(); return (baos.toByteArray()); }
From source file:com.github.harmanpa.jrecon.utils.Compression.java
public static byte[] decompress(byte[] data) throws IOException { InputStream is = new BZip2CompressorInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream baos = new ByteArrayOutputStream(128); int b;/*from ww w . ja v a 2s .co m*/ while ((b = is.read()) > -1) { baos.write(b); } is.close(); return baos.toByteArray(); }
From source file:com.taobao.tdhs.client.protocol.TDHSProtocolBinary.java
protected static void writeInt8ToStream(int v, ByteArrayOutputStream out) { out.write((byte) (v & 0XFF)); }
From source file:Main.java
public static byte[] toBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); int ch;//from w ww .j a v a2 s. c o m while ((ch = in.read()) != -1) { out.write(ch); } byte buffer[] = out.toByteArray(); out.close(); return buffer; }
From source file:Main.java
/** * read inputstream and return the byte array * @param inputStream//from ww w .j a va 2 s . c o m * @return * @throws IOException */ public static byte[] readBytesFromInputStream(InputStream inputStream) throws IOException { if (inputStream == null) { Log.e(TAG, "invalid inputStream"); return null; } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int read = inputStream.read(); while (read != -1) { byteArrayOutputStream.write(read); read = inputStream.read(); } return byteArrayOutputStream.toByteArray(); }
From source file:Main.java
/** * read inputstream and return the byte array * @param inputStream// w w w .j av a 2 s . c o m * @return * @throws IOException */ public static byte[] readBytesFromInputStream(InputStream inputStream) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int read = inputStream.read(); while (read != -1) { byteArrayOutputStream.write(read); read = inputStream.read(); } return byteArrayOutputStream.toByteArray(); }
From source file:Main.java
/** * Converts a DER-encoded Oid from an InputStream to a dot-separated * String representation.//from w ww .java2 s . c o m * * @param oid DER-encoded Oid InputStream * @return Oid in dot-separated String representation * */ public static byte[] OidStream2DER(InputStream oid) throws IOException { int tag; int length; ByteArrayOutputStream outOid = new ByteArrayOutputStream(); try { tag = oid.read(); length = oid.read(); outOid.write(tag); outOid.write(length); for (int i = 0; i < length; i++) { outOid.write(oid.read()); } } catch (IOException e) { throw new IOException("I/O Error occurred when reading InputStream"); } return outOid.toByteArray(); }
From source file:Main.java
public static String ConvertToString(InputStream is) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = -1;/*w w w .j a v a 2 s .c om*/ try { while ((i = is.read()) != -1) { baos.write(i); } return baos.toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return ""; }