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 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();
}
use of java.util.zip.DeflaterOutputStream in project OpenAM by OpenRock.
the class SAML2Utils method encodeForRedirect.
/**
* Returns the encoded request message.
* The SAML Request message must be
* encoded before being transmitted.
* The Request message is encoded as follows:
* 1. URL Encoded using the DEFLATE compression method.
* 2. Then the message is base-64 encoded according to
* the rules specified in RFC2045.
*
* @param str String to be encoded.
* @return String the encoded String value or null on error.
*/
public static String encodeForRedirect(final String str) {
String classMethod = "SAML2Utils.encodeForRedirect: ";
byte[] input;
try {
input = str.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
debug.error(classMethod + "cannot get byte array: ", uee);
return null;
}
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(out, deflater);
try {
deflaterOutputStream.write(input);
} catch (IOException e) {
debug.error(classMethod + "There was a problem compressing the input", e);
return null;
} finally {
IOUtils.closeIfNotNull(deflaterOutputStream);
}
String encoded = URLEncDec.encode(Base64.encode(out.toByteArray()));
if (debug.messageEnabled()) {
debug.message(classMethod + "out string length : " + encoded.length());
debug.message(classMethod + "out string is ===>" + encoded + "<===");
}
return encoded;
}
Aggregations