List of usage examples for java.io ByteArrayOutputStream close
public void close() throws IOException
From source file:Main.java
public static void freeeOutputStream(Object stream) { if (stream instanceof ByteArrayOutputStream) { ByteArrayOutputStream outputFormat = (ByteArrayOutputStream) stream; try {/*from w ww .j av a 2 s . co m*/ outputFormat.close(); } catch (IOException e) { e.printStackTrace(); } finally { outputFormat = null; } } System.gc(); }
From source file:Main.java
/** * /*from www.jav a 2 s. c o m*/ * @param in The InputStream to read the bytes from. * @return A byte array containing the bytes that were read. * @throws IOException If I/O error occurred. */ public static final byte[] readFully(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); transfer(in, out); out.close(); return out.toByteArray(); }
From source file:com.klarna.hiverunner.builder.HiveResource.java
private static ByteArrayOutputStream createOutputStream(byte[] data) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(data);/* w ww . java 2s . c o m*/ baos.close(); return baos; }
From source file:Main.java
public static byte[] toBytes(Bitmap bmp) { // Default size is 32 bytes ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {/*from w ww . ja v a 2 s . c o m*/ bmp.compress(CompressFormat.JPEG, 100, bos); bos.close(); } catch (IOException e) { e.printStackTrace(); } return bos.toByteArray(); }
From source file:Main.java
public static String bitmapToBase64(Bitmap bitmap) { try {//from w ww . j a v a 2 s. c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); baos.close(); byte[] buffer = baos.toByteArray(); String photo = Base64.encodeToString(buffer, 0, buffer.length, Base64.DEFAULT); return photo; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.amazonaws.services.kinesis.producer.KinesisProducerConfigurationTest.java
private static String writeFile(Properties p) { try {//ww w .j a v a 2 s.c o m 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:Main.java
private static byte[] readInputStream(InputStream inputStream) throws IOException { byte[] buffer = new byte[8192]; int len = 0;/*from w w w.j a v a2s .com*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((len = inputStream.read(buffer)) != -1) { bos.write(buffer, 0, len); } bos.close(); return bos.toByteArray(); }
From source file:Main.java
public static byte[] getBitmapByte(Bitmap bitmap) { ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); try {//from ww w . ja va2 s. co m out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); }
From source file:Main.java
private static byte[] readBitmap(Bitmap bmp) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 60, baos); try {/*from w w w .j a va 2 s .c o m*/ baos.flush(); baos.close(); } catch (IOException e) { e.printStackTrace(); } return baos.toByteArray(); }
From source file:Main.java
public static byte[] getBitmapByte(Bitmap bitmap) { ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); try {//from w ww. ja v a 2 s . c o m out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); }