Example usage for java.io ByteArrayOutputStream ByteArrayOutputStream

List of usage examples for java.io ByteArrayOutputStream ByteArrayOutputStream

Introduction

In this page you can find the example usage for java.io ByteArrayOutputStream ByteArrayOutputStream.

Prototype

public ByteArrayOutputStream() 

Source Link

Document

Creates a new ByteArrayOutputStream .

Usage

From source file:Main.java

public static String getStringFromInput(InputStream in) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    int c = 0;//from   w  ww .  jav a2 s  . c  om
    byte[] buffer = new byte[1024];
    try {
        while ((c = in.read(buffer)) != -1) {
            bos.write(buffer, 0, c);
        }
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new String(bos.toByteArray());
}

From source file:Main.java

public static byte[] getBitmapByte(Bitmap bitmap) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    try {//www  .ja va2 s .co  m
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return out.toByteArray();
}

From source file:Main.java

public static String readInputStream(InputStream is) {
    try {/*www  .  ja va2 s . c  om*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int len = 0;
        byte[] buffer = new byte[1024];
        while ((len = is.read(buffer)) != -1) {
            baos.write(buffer, 0, len);
        }
        is.close();
        baos.close();
        byte[] result = baos.toByteArray();
        String temp = new String(result);
        return temp;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(CompressFormat.PNG, 100, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] load(InputStream is) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int len;/*from   w  w w.jav  a 2  s  .c  om*/
    while ((len = is.read(buffer)) != -1)
        baos.write(buffer, 0, len);
    baos.close();
    is.close();
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm) {
    if (bm == null)
        return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static byte[] bitmapToByteArray(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] array = stream.toByteArray();
    try {/*from w w  w .j av  a 2  s  .c  o m*/
        stream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return array;

}

From source file:Main.java

public static String BitmapToByte(Bitmap bitmap) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 50, byteArrayOutputStream);
    return new String(Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT));
}

From source file:Main.java

public static String toBase64(Bitmap bitmap) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
    byte[] byteArray = byteArrayOutputStream.toByteArray();

    return Base64.encodeToString(byteArray, Base64.DEFAULT);
}

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(CompressFormat.PNG, 100, baos);
    bm.recycle();/* w w  w .  java  2 s.com*/
    return baos.toByteArray();
}