List of usage examples for java.io ByteArrayOutputStream toByteArray
public synchronized byte[] toByteArray()
From source file:com.amazonaws.services.kinesis.producer.KinesisProducerConfigurationTest.java
private static String writeFile(Properties p) { try {//w w w . j av a2 s. c om ByteArrayOutputStream baos = new ByteArrayOutputStream(); p.store(baos, ""); baos.close(); return writeFile(new String(baos.toByteArray(), "UTF-8")); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.github.harmanpa.jrecon.utils.Compression.java
public static byte[] decompress(byte[] data) throws IOException { InputStream is = new BZip2CompressorInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream baos = new ByteArrayOutputStream(128); int b;/*from ww w . ja v a 2 s. c o m*/ while ((b = is.read()) > -1) { baos.write(b); } is.close(); return baos.toByteArray(); }
From source file:Main.java
public static int getByteCount(Bitmap bitmap, Bitmap.CompressFormat mCompressFormat) { int size = 0; ByteArrayOutputStream output = null; try {//from ww w . j ava 2s .c om output = new ByteArrayOutputStream(); bitmap.compress(mCompressFormat, 100, output); byte[] result = output.toByteArray(); size = result.length; result = null; } catch (Exception e) { e.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (Exception e) { e.printStackTrace(); } } } return size; }
From source file:Main.java
public static byte[] getImage(final InputStream inputStream) { byte images[] = null; try {/*from w w w.j a v a2 s . c o m*/ // final BufferedImage image = ImageIO.read(new File( // "d:\\images\\peacock.jpg")); final BufferedImage image = ImageIO.read(inputStream); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpeg", baos); // ImageIO.write(image, "jpeg", new File("D:\\images.jpeg")); images = baos.toByteArray(); } catch (final Exception e) { e.printStackTrace(); } return images; }
From source file:ByteUtils.java
public static byte[] packRaw(byte[] b) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream zos = new GZIPOutputStream(baos); zos.write(b);//from w ww. jav a2s . co m zos.close(); return baos.toByteArray(); }
From source file:Main.java
public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(src);//w ww . ja v a2s. c om ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); @SuppressWarnings("unchecked") List<T> dest = (List<T>) in.readObject(); return dest; }
From source file:Main.java
@NonNull public static byte[] bitmapToByteArray(@NonNull Bitmap bitmap) { ByteArrayOutputStream out = null; try {/*from w w w .java 2s.c o m*/ out = new ByteArrayOutputStream(bitmap.getWidth() * bitmap.getHeight()); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); return out.toByteArray(); } finally { if (out != null) try { out.close(); } catch (Exception ignore) { } } }
From source file:com.mirth.connect.connectors.http.HttpUtil.java
public static byte[] compressGzip(String content, String charset) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); gzos.write(content.getBytes(charset)); gzos.close();// w w w .ja v a 2s .c o m 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 av a 2 s. c o m*/ while ((count = in.read(data, 0, 4096)) != -1) outStream.write(data, 0, count); return outStream.toByteArray(); }