Example usage for java.io ByteArrayOutputStream toByteArray

List of usage examples for java.io ByteArrayOutputStream toByteArray

Introduction

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

Prototype

public synchronized byte[] toByteArray() 

Source Link

Document

Creates a newly allocated byte array.

Usage

From source file:Main.java

/**
 * //from  w  w  w . j a v a 2s.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:Main.java

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

    return byteArray;
}

From source file:Main.java

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

    return byteArray;
}

From source file:Main.java

public static byte[] getByteArray(Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }//from  www  .  j  a  v  a2s . com

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
    return out.toByteArray();
}

From source file:Main.java

public static byte[] BitmapToByteArray(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] byteArray = stream.toByteArray();

    return byteArray;
}

From source file:Main.java

public static byte[] BitmapBytes(Bitmap bm) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
    return baos.toByteArray();
}

From source file:Main.java

public static InputStream bitmap2InputStream(Bitmap bm, Bitmap.CompressFormat format, int quality) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(format, quality, baos);/* w  w  w . j  a  v a  2  s  . c  om*/
    InputStream is = new ByteArrayInputStream(baos.toByteArray());
    return is;
}

From source file:Main.java

public static byte[] bitmap2Bytes(Bitmap bm) {
    if (null == bm) {
        return null;
    }/*ww w.  j a v a2 s .c om*/
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return baos.toByteArray();
    } catch (OutOfMemoryError e) {
    }

    return null;
}

From source file:it.sonarlint.cli.tools.CommandExecutor.java

private static String getLogs(ByteArrayOutputStream stream) {
    return new String(stream.toByteArray(), Charset.defaultCharset());
}

From source file:Main.java

public static String getImageAsString(Bitmap bmp) {
    ByteArrayOutputStream bYtE = new ByteArrayOutputStream();

    bmp.compress(Bitmap.CompressFormat.JPEG, 100, bYtE);
    byte[] byteArray = bYtE.toByteArray();
    String image = Base64.encodeToString(byteArray, Base64.DEFAULT);
    bmp.recycle();//from   www.ja v a2 s. c  om
    Log.d("Converted TO : ", image);
    return image;
}