List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
/** * BitMap2Byte/*from www. j ava 2 s .co m*/ * * @param bitmap * @return */ public static byte[] getBitmapByte(Bitmap bitmap) { ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); }
From source file:Main.java
/** * This method converts a bitmap image to a byte array. * * @param bm/*w w w.ja v a 2 s. c o m*/ * @return */ public static byte[] getBytesFromBitmap(Bitmap bm) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, stream); return stream.toByteArray(); }
From source file:Main.java
public static byte[] readNetWorkInputStream(InputStream in) { ByteArrayOutputStream os = null; try {/*from w ww . jav a2 s . com*/ os = new ByteArrayOutputStream(); int readCount = 0; int len = 1024; byte[] buffer = new byte[len]; while ((readCount = in.read(buffer)) != -1) { os.write(buffer, 0, readCount); } in.close(); in = null; return os.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { if (null != os) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } os = null; } } return null; }
From source file:Main.java
public static String convertToBase64(Bitmap bmp) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 80, stream); byte[] byteArray = stream.toByteArray(); try {//from w w w. ja v a 2 s . c om stream.close(); } catch (IOException e) { e.printStackTrace(); } return Base64.encodeToString(byteArray, Base64.DEFAULT); }
From source file:Main.java
private static InputStream bitmapToStream(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100, baos); InputStream sbs = new ByteArrayInputStream(baos.toByteArray()); return sbs;/*from w w w . ja v a 2 s . com*/ }
From source file:Main.java
public static byte[] decompressGZIP(byte bytes[]) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(bytes); GZIPInputStream gzipis = new GZIPInputStream(is); ByteArrayOutputStream os = new ByteArrayOutputStream(); int i;/* w ww . java 2 s. c o m*/ while ((i = gzipis.read()) != -1) { os.write(i); } gzipis.close(); os.close(); return os.toByteArray(); }
From source file:MainClass.java
public static byte[] makeBytes(long t, double q) { try {// ww w . j a v a 2s. c o m ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(byteOut); dataOut.writeLong(t); dataOut.writeDouble(q); return byteOut.toByteArray(); } catch (IOException e) { return new byte[0]; } }
From source file:Main.java
public static InputStream bitmap2InputStream(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is;/*w ww . ja v a 2 s . co m*/ }
From source file:Main.java
public final static byte[] BitmapChangeByte(Bitmap btm) { if (btm == null) { return null; }/*from ww w .j av a2 s . co m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); btm.compress(CompressFormat.PNG, 100, baos); byte[] data2 = baos.toByteArray(); return data2; }
From source file:Main.java
public static byte[] readFully(File file) throws IOException { final InputStream in = new BufferedInputStream(new FileInputStream(file)); try {// w w w. j a v a 2s . c o m ByteArrayOutputStream bytes = new ByteArrayOutputStream(); byte[] buffer = new byte[1 << 20]; int count; while ((count = in.read(buffer)) != -1) { bytes.write(buffer, 0, count); } return bytes.toByteArray(); } finally { in.close(); } }