List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
private static String readStream(InputStream is) { try {// ww w .j av a 2 s . c o m ByteArrayOutputStream bo = new ByteArrayOutputStream(); int i = is.read(); while (i != -1) { bo.write(i); i = is.read(); } return bo.toString(); } catch (IOException e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static byte[] extract(InputStream inputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int read = 0; while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) { baos.write(buffer, 0, read);/* w ww . java 2 s .c om*/ } baos.flush(); return baos.toByteArray(); }
From source file:Main.java
public static byte[] bitmapToByteArray(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray(); return byteArray; }
From source file:Main.java
public static String readString(byte[] message, int start) { int pos = start; final int len = message.length; ByteArrayOutputStream os = new ByteArrayOutputStream(); while (pos < len) { if (message[pos] == '\0') { ++pos;//from www. jav a 2 s .co m break; } os.write(message[pos++]); } return os.toString(); }
From source file:Main.java
public static String convertStreamToString(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = is.read(); while (i != -1) { baos.write(i);/*w w w . j a v a 2s.co m*/ i = is.read(); } return baos.toString(); }
From source file:Main.java
public static byte[] extract(InputStream inputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int read;/*from ww w .j a v a 2 s. c o m*/ while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) { baos.write(buffer, 0, read); } baos.flush(); return baos.toByteArray(); }
From source file:Main.java
public static byte[] getByte(String ss) { String[] shil = ss.split(" "); StringBuilder er = new StringBuilder(); ByteArrayOutputStream out = new ByteArrayOutputStream(); for (String string : shil) { if ("".equals(string)) { continue; }/* w w w. j a va 2 s .c om*/ int i = Integer.valueOf(string, 16); out.write(i); } return out.toByteArray(); }
From source file:Main.java
/** * Converts a given bitmap to byte array **///from www. j a v a 2s . co m public static byte[] toBytes(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); return stream.toByteArray(); }
From source file:Main.java
public static byte[] getBitmap2Bytes(Bitmap photo) { if (photo == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
public static byte[] gzip(byte[] data) { byte[] b = null; try {/*from ww w. j a va 2s.c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(bos); gzip.write(data); gzip.finish(); gzip.close(); b = bos.toByteArray(); bos.close(); } catch (Exception ex) { ex.printStackTrace(); } return b; }