use of java.util.zip.DeflaterOutputStream in project cloudstack by apache.
the class SAMLUtils method encodeSAMLRequest.
public static String encodeSAMLRequest(XMLObject authnRequest) throws MarshallingException, IOException {
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(authnRequest);
Element authDOM = marshaller.marshall(authnRequest);
StringWriter requestWriter = new StringWriter();
XMLHelper.writeNode(authDOM, requestWriter);
String requestMessage = requestWriter.toString();
Deflater deflater = new Deflater(Deflater.DEFLATED, true);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater);
deflaterOutputStream.write(requestMessage.getBytes(Charset.forName("UTF-8")));
deflaterOutputStream.close();
String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES);
encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim();
return encodedRequestMessage;
}
use of java.util.zip.DeflaterOutputStream in project gerrit by GerritCodeReview.
the class DiffSummary method writeObject.
private void writeObject(ObjectOutputStream output) throws IOException {
writeVarInt32(output, insertions);
writeVarInt32(output, deletions);
writeVarInt32(output, paths.length);
try (DeflaterOutputStream out = new DeflaterOutputStream(output)) {
for (String p : paths) {
writeString(out, p);
}
}
}
use of java.util.zip.DeflaterOutputStream in project jdk8u_jdk by JetBrains.
the class MyOutputStream method main.
public static void main(String[] args) throws Exception {
/* initialise stuff here */
File fn = new File("x.WriteBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte[] b = new byte[64];
for (int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test for different output streams */
FileOutputStream fos = new FileOutputStream(fn);
doTest(fos);
doTest1(fos);
fos.close();
ObjectOutputStream oos = new ObjectOutputStream(new MyOutputStream());
doTest(oos);
doTest1(oos);
oos.close();
BufferedOutputStream bos = new BufferedOutputStream(new MyOutputStream());
doTest(bos);
doTest1(bos);
bos.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doTest(baos);
doTest1(baos);
baos.close();
DataOutputStream dos = new DataOutputStream(new MyOutputStream());
doTest(dos);
doTest1(dos);
dos.close();
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream();
pos.connect(pis);
doTest(pos);
doTest1(pos);
pos.close();
DeflaterOutputStream dfos = new DeflaterOutputStream(new MyOutputStream());
doTest(dfos);
doTest1(dfos);
dfos.close();
/* cleanup */
fn.delete();
}
use of java.util.zip.DeflaterOutputStream in project logging-log4j2 by apache.
the class GelfLayout method compress.
private byte[] compress(final byte[] bytes) {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream(compressionThreshold / 8);
try (final DeflaterOutputStream stream = compressionType.createDeflaterOutputStream(baos)) {
if (stream == null) {
return bytes;
}
stream.write(bytes);
stream.finish();
}
return baos.toByteArray();
} catch (final IOException e) {
StatusLogger.getLogger().error(e);
return bytes;
}
}
use of java.util.zip.DeflaterOutputStream in project cloudstack by apache.
the class SecurityGroupRulesCmd method compressStringifiedRules.
/**
* Compress the security group rules using zlib compression to allow the call to the hypervisor
* to scale beyond 8k cidrs.
* Note : not using {@see GZipOutputStream} since that is for files, using {@see DeflaterOutputStream} instead.
* {@see GZipOutputStream} gives a different header, although the compression is the same
*/
public String compressStringifiedRules() {
final String stringified = stringifyRules();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
String encodedResult = null;
try {
final DeflaterOutputStream dzip = new DeflaterOutputStream(out);
dzip.write(stringified.getBytes());
dzip.close();
encodedResult = Base64.encodeBase64String(out.toByteArray());
} catch (final IOException e) {
LOGGER.warn("Exception while compressing security group rules");
}
return encodedResult;
}
Aggregations