use of java.util.zip.DeflaterOutputStream in project platform_frameworks_base by android.
the class BlobBackupHelper method deflate.
// Also versions the deflated blob internally in case we need to revise it
private byte[] deflate(byte[] data) {
byte[] result = null;
if (data != null) {
try {
ByteArrayOutputStream sink = new ByteArrayOutputStream();
DataOutputStream headerOut = new DataOutputStream(sink);
// write the header directly to the sink ahead of the deflated payload
headerOut.writeInt(mCurrentBlobVersion);
DeflaterOutputStream out = new DeflaterOutputStream(sink);
out.write(data);
// finishes and commits the compression run
out.close();
result = sink.toByteArray();
if (DEBUG) {
Log.v(TAG, "Deflated " + data.length + " bytes to " + result.length);
}
} catch (IOException e) {
Log.w(TAG, "Unable to process payload: " + e.getMessage());
}
}
return result;
}
use of java.util.zip.DeflaterOutputStream in project netty by netty.
the class ZlibTest method deflate.
private static byte[] deflate(byte[] bytes) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream stream = new DeflaterOutputStream(out);
stream.write(bytes);
stream.close();
return out.toByteArray();
}
use of java.util.zip.DeflaterOutputStream in project hadoop by apache.
the class CompressedWritable method write.
@Override
public final void write(DataOutput out) throws IOException {
if (compressed == null) {
ByteArrayOutputStream deflated = new ByteArrayOutputStream();
Deflater deflater = new Deflater(Deflater.BEST_SPEED);
DataOutputStream dout = new DataOutputStream(new DeflaterOutputStream(deflated, deflater));
writeCompressed(dout);
dout.close();
deflater.end();
compressed = deflated.toByteArray();
}
out.writeInt(compressed.length);
out.write(compressed);
}
use of java.util.zip.DeflaterOutputStream in project intellij-community by JetBrains.
the class RefCountingStorage method zipAndWrite.
private void zipAndWrite(ByteSequence bytes, int record, boolean fixedSize) throws IOException {
BufferExposingByteArrayOutputStream s = new BufferExposingByteArrayOutputStream();
DeflaterOutputStream out = new DeflaterOutputStream(s);
try {
out.write(bytes.getBytes(), bytes.getOffset(), bytes.getLength());
} finally {
out.close();
}
synchronized (myLock) {
doWrite(record, fixedSize, s);
myPendingWriteRequestsSize -= bytes.getLength();
myPendingWriteRequests.remove(record);
}
}
use of java.util.zip.DeflaterOutputStream in project OpenAM by OpenRock.
the class IOUtilsTest method getObjectStreamBytes.
private byte[] getObjectStreamBytes(Object in, boolean compress) throws IOException {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ObjectOutputStream objectOutputStream = compress ? new ObjectOutputStream(new DeflaterOutputStream(byteArrayOutputStream)) : new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(in);
objectOutputStream.close();
return byteArrayOutputStream.toByteArray();
}
Aggregations