Search in sources :

Example 86 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project commons by twitter.

the class AssetHandlerTest method expectPayload.

private static ByteArrayOutputStream expectPayload(HttpServletResponse resp) throws Exception {
    ByteArrayOutputStream responseBody = new ByteArrayOutputStream();
    expect(resp.getOutputStream()).andReturn(new FakeServletOutputStream(responseBody));
    return responseBody;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 87 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project commons by twitter.

the class Base64ZlibCodecTest method testDecodeGzip.

public void testDecodeGzip() throws Exception {
    final byte[] input = createRandomBytes(10240);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    final OutputStream os = new GZIPOutputStream(new Base64OutputStream(out));
    os.write(input);
    os.close();
    final String encoded = new String(out.toByteArray(), "8859_1");
    assertTrue(encoded.startsWith("H4sIAAAAAAAAA"));
    Assert.assertArrayEquals(input, Base64ZlibCodec.decode(encoded));
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream)

Example 88 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project commons by twitter.

the class CodecTestUtilities method serialize.

static <T> byte[] serialize(Codec<T> codec, T item) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    codec.serialize(item, out);
    return out.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 89 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project adt4j by sviperll.

the class MainTest method testSerialization.

@Test
public void testSerialization() throws IOException, ClassNotFoundException {
    UserKey userKey1 = UserKey.valueOf(1);
    ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
    ObjectOutputStream outputStream = new ObjectOutputStream(byteArray);
    outputStream.writeObject(userKey1);
    ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(byteArray.toByteArray()));
    UserKey userKey2 = (UserKey) inputStream.readObject();
    assertTrue("userKey1.equals(userKey2)", userKey1.equals(userKey2));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UserKey(com.github.sviperll.adt4j.examples.UserKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 90 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project Android-ImageResizer by svenkapudija.

the class ImageWriter method writeToFile.

public static boolean writeToFile(Bitmap image, File file) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    image.compress(CompressFormat.JPEG, 100, bytes);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(bytes.toByteArray());
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

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