List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream
public ByteArrayOutputStream()
From source file:Main.java
public static byte[] bmp2byteArray(Bitmap bitmap, Bitmap.CompressFormat format, int compressVal) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(format, compressVal, baos); return baos.toByteArray(); }
From source file:Main.java
public static String marshal(Object o) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); marshal(o, bos, new HashMap<String, Object>()); return bos.toString(); }
From source file:Main.java
private static String storeImage(Context context, Bitmap bitmap) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes); File f = null;/* ww w .j a v a 2 s . c om*/ try { f = File.createTempFile("citationsImg", ".png", context.getExternalCacheDir()); FileOutputStream fo = new FileOutputStream(f); fo.write(bytes.toByteArray()); fo.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return f.getAbsolutePath(); }
From source file:Main.java
private static byte[] createByteArrayFromBitmap(Bitmap bitmap) { Log.e(LOG_TAG, "creating asset"); final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream); Log.e(LOG_TAG, "length : " + Integer.toString(byteStream.toByteArray().length)); return byteStream.toByteArray(); }
From source file:Main.java
public static byte[] compress(byte[] src) throws IOException { GZIPOutputStream gzip = null; ByteArrayOutputStream baos = null; try {// w w w . jav a 2s .c o m baos = new ByteArrayOutputStream(); gzip = new GZIPOutputStream(baos); gzip.write(src); gzip.finish(); return baos.toByteArray(); } finally { if (gzip != null) { gzip.close(); } if (baos != null) { baos.close(); } } }
From source file:Main.java
public static void bitmapToFile(Bitmap bitmap, File file) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); byte[] bitmapdata = bos.toByteArray(); FileOutputStream fos;//from ww w . j a va2 s . com try { fos = new FileOutputStream(file); fos.write(bitmapdata); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static byte[] toByteArray(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output);// w w w.j av a 2 s .co m return output.toByteArray(); }
From source file:Main.java
public static byte[] compress(Bitmap bitmap, int persentage) { if (bitmap == null) return new byte[0]; if (persentage <= 0) persentage = 0;/* w w w . j a v a2 s. co m*/ else if (persentage > 100) persentage = 100; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, persentage, baos); return baos.toByteArray(); }
From source file:Main.java
/** * Write stream to bytes array.//from w w w .j a v a2 s . c o m * * @param source stream * @return bytes array */ public static byte[] streamToBytes(InputStream source) { ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int l; try { while ((l = source.read(buffer)) >= 0) { result.write(buffer, 0, l); } } catch (IOException e) { throw new RuntimeException(e); } return result.toByteArray(); }
From source file:Main.java
/** * uncompress the xmlByteArray/*from ww w . ja va 2 s. c om*/ */ public static byte[] uncompressByteArray(byte[] xmlByteArray) throws IOException { byte[] tmp = new byte[2048]; int byteCount = 0; ByteArrayOutputStream uncompressedData = new ByteArrayOutputStream(); GZIPInputStream gzipIS = new GZIPInputStream(new ByteArrayInputStream(xmlByteArray)); while ((byteCount = gzipIS.read(tmp)) != -1) { uncompressedData.write(tmp, 0, byteCount); } return uncompressedData.toByteArray(); }