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 outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0;/*from ww w. j av a 2s .c o m*/ while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } outStream.close(); return outStream.toByteArray(); }
From source file:Main.java
public static String bitmapToBase64(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; }
From source file:Main.java
public static byte[] toBytes(Bitmap bitmap) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, PNG_SAVE_QUALITY, outputStream); return outputStream.toByteArray(); }
From source file:Main.java
public static byte[] readStream(InputStream in) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = in.read(buffer)) != -1) { outputStream.write(buffer, 0, len); }// w w w.ja v a2 s. com outputStream.close(); in.close(); return outputStream.toByteArray(); }
From source file:Main.java
public static String bitmapBase64(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] bytes = baos.toByteArray(); return Base64.encodeToString(bytes, 0); }
From source file:Main.java
public static byte[] getBytes(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0;/* w w w. ja v a2 s .c o m*/ while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } outStream.close(); inStream.close(); return outStream.toByteArray(); }
From source file:Main.java
private static String getStringImage(Bitmap bmp) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; }
From source file:Main.java
public static String BitmapToBase64(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); return Base64.encodeToString(imageBytes, Base64.DEFAULT); }
From source file:Main.java
public static byte[] readInputStream(InputStream is) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); final int blockSize = 8192; byte[] buffer = new byte[blockSize]; int count = 0; try {/* w w w . ja va2s. c o m*/ while ((count = is.read(buffer, 0, blockSize)) > 0) { byteStream.write(buffer, 0, count); } return byteStream.toByteArray(); } catch (Exception e) { return null; } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } } }
From source file:Main.java
public static byte[] getImageBytes(Bitmap bmp) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return imageBytes; }