Search in sources :

Example 56 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.

the class ZipCombinerTest method testCompressedDontCare.

@Test
public void testCompressedDontCare() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
        zipCombiner.addZip(sampleZip());
    }
    FakeZipFile expectedResult = new FakeZipFile().addEntry("hello.txt", "Hello World!", true);
    expectedResult.assertSame(out.toByteArray());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 57 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project ADWLauncher2 by boombuler.

the class ItemInfo method flattenBitmap.

static byte[] flattenBitmap(Bitmap bitmap) {
    // Try go guesstimate how much space the icon will take when serialized
    // to avoid unnecessary allocations/copies during the write.
    int size = bitmap.getWidth() * bitmap.getHeight() * 4;
    ByteArrayOutputStream out = new ByteArrayOutputStream(size);
    try {
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
        return out.toByteArray();
    } catch (IOException e) {
        Log.w("Favorite", "Could not write icon");
        return null;
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 58 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project ADWLauncher2 by boombuler.

the class Utilities method flattenBitmap.

public static byte[] flattenBitmap(Bitmap bitmap) {
    // Try go guesstimate how much space the icon will take when serialized
    // to avoid unnecessary allocations/copies during the write.
    int size = bitmap.getWidth() * bitmap.getHeight() * 4;
    ByteArrayOutputStream out = new ByteArrayOutputStream(size);
    try {
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
        return out.toByteArray();
    } catch (IOException e) {
        Log.w("Favorite", "Could not write icon");
        return null;
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 59 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project VirtualApp by asLody.

the class FileUtils method toByteArray.

public static byte[] toByteArray(InputStream inStream) throws IOException {
    ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
    byte[] buff = new byte[100];
    int rc;
    while ((rc = inStream.read(buff, 0, 100)) > 0) {
        swapStream.write(buff, 0, rc);
    }
    return swapStream.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 60 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project baker-android by bakerframework.

the class AndroidHttpClient method getCompressedEntity.

/**
     * Compress data to send to server.
     * Creates a Http Entity holding the gzipped data.
     * The data will not be compressed if it is too short.
     * @param data The bytes to compress
     * @return Entity holding the data
     */
public static AbstractHttpEntity getCompressedEntity(byte[] data, ContentResolver resolver) throws IOException {
    AbstractHttpEntity entity;
    if (data.length < getMinGzipSize(resolver)) {
        entity = new ByteArrayEntity(data);
    } else {
        ByteArrayOutputStream arr = new ByteArrayOutputStream();
        OutputStream zipper = new GZIPOutputStream(arr);
        zipper.write(data);
        zipper.close();
        entity = new ByteArrayEntity(arr.toByteArray());
        entity.setContentEncoding("gzip");
    }
    return entity;
}
Also used : ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)8438 Test (org.junit.Test)2232 ByteArrayInputStream (java.io.ByteArrayInputStream)2148 IOException (java.io.IOException)2037 PrintStream (java.io.PrintStream)800 InputStream (java.io.InputStream)765 ObjectOutputStream (java.io.ObjectOutputStream)759 DataOutputStream (java.io.DataOutputStream)705 ObjectInputStream (java.io.ObjectInputStream)361 File (java.io.File)331 OutputStream (java.io.OutputStream)318 HashMap (java.util.HashMap)279 ArrayList (java.util.ArrayList)264 FileInputStream (java.io.FileInputStream)211 OutputStreamWriter (java.io.OutputStreamWriter)207 DataInputStream (java.io.DataInputStream)198 Test (org.testng.annotations.Test)184 PrintWriter (java.io.PrintWriter)162 URL (java.net.URL)160 Map (java.util.Map)158