List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
public static byte[] readStream(InputStream inStream) throws Exception { ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = inStream.read(buffer)) != -1) { outSteam.write(buffer, 0, len);/*from w w w. j ava2s.c o m*/ } outSteam.close(); inStream.close(); return outSteam.toByteArray(); }
From source file:Main.java
public static String toXml(Object o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(baos); e.writeObject(o);/*from ww w . j a v a 2 s . co m*/ e.close(); return baos.toString(); }
From source file:Main.java
public static byte[] path2Bytes(String path) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BitmapFactory.decodeFile(path).compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
From source file:Main.java
public static byte[] getBytesFromInputStream(InputStream in) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] data = new byte[4096]; int count;/*from w w w. j a v a2s. c o m*/ while ((count = in.read(data, 0, 4096)) != -1) outStream.write(data, 0, count); return outStream.toByteArray(); }
From source file:Main.java
public static byte[] getByteArrayFromBitmap(final Bitmap bitmap, int quality) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, out); return out.toByteArray(); }
From source file:Main.java
public static String BitMapToString(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] arr = baos.toByteArray(); String result = Base64.encodeToString(arr, Base64.DEFAULT); return result; }
From source file:Main.java
public static String BitmapToBase64PNG(Bitmap bmp) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 40, baos); byte[] data = baos.toByteArray(); return Base64.encodeToString(data, Base64.DEFAULT); }
From source file:Main.java
public static byte[] readStream(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0;/*w w w .jav a2 s. co m*/ while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } outStream.close(); inStream.close(); return outStream.toByteArray(); }
From source file:Main.java
public static String bitmapToString(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] arr = baos.toByteArray(); String result = Base64.encodeToString(arr, Base64.DEFAULT); return result; }
From source file:Main.java
public static byte[] readStream(InputStream inStream) throws Exception { ByteArrayOutputStream outstream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = inStream.read(buffer)) != -1) { outstream.write(buffer, 0, len); }/*from ww w . j a va 2s .co m*/ outstream.close(); inStream.close(); return outstream.toByteArray(); }