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