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;
}
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));
}
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();
}
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));
}
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;
}
Aggregations