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

public static InputStream Bitmap2IS(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 70, baos);
    InputStream sbs = new ByteArrayInputStream(baos.toByteArray());
    return sbs;//from  w  w w .  jav a2 s  . c  o m
}

From source file:Main.java

public static InputStream bitmap2InputStream4Gif(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.WEBP, 100, baos);
    InputStream is = new ByteArrayInputStream(baos.toByteArray());
    return is;/*w w w.  j  a va 2 s.c o m*/
}

From source file:Main.java

public static String printDocument(Document doc, boolean prettyPrint) throws IOException, TransformerException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    printDocument(doc, baos, prettyPrint);
    return new String(baos.toByteArray());
}

From source file:Main.java

public static void bitmapToFile(Context mContext, File mFile, Bitmap mBitmap) throws Exception {

    //Convert bitmap to byte array
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    mBitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
    byte[] bitmapdata = bos.toByteArray();

    //write the bytes in file
    FileOutputStream fos = new FileOutputStream(mFile);
    fos.write(bitmapdata);//from w  ww  . ja  v  a2 s . co  m
}

From source file:Main.java

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

From source file:Main.java

public static InputStream Bitmap2InputStream(Bitmap bm) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    InputStream is = new ByteArrayInputStream(baos.toByteArray());
    return is;/*from   www .j  a  v a2s.  c om*/
}

From source file:com.siemens.sw360.exporter.CSVExport.java

@NotNull
public static ByteArrayInputStream createCSV(Iterable<String> csvHeaderIterable,
        Iterable<Iterable<String>> inputIterable) throws IOException {
    final ByteArrayOutputStream outB = getCSVOutputStream(csvHeaderIterable, inputIterable);

    return new ByteArrayInputStream(outB.toByteArray());
}

From source file:Main.java

/**
 * Compresses a bitmap into a PNG and converts into a Base64 encoded string.
 * The encoded string can be decoded using {@link decodeBitmapFromString(String)}.
 * @param bitmap The Bitmap to compress and encode.
 * @return the String encoding the Bitmap.
 *///from   w w w. ja v a 2  s .  c om
public static String encodeBitmapAsString(Bitmap bitmap) {
    if (bitmap == null)
        return "";
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
    return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT);
}

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;/*  w  ww .j a  va  2 s.  c  om*/
    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 String bmpToStrBase64(Bitmap bitmap) {

    Bitmap bm = bitmap;//from  w ww.  j a v a2  s . c  om
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 80, stream); //bm is the bitmap object
    byte[] b = stream.toByteArray();
    String strBase64 = Base64.encodeToString(b, 0);

    return strBase64;
}