Search in sources :

Example 61 with DeflaterOutputStream

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;
}
Also used : Marshaller(org.opensaml.xml.io.Marshaller) StringWriter(java.io.StringWriter) Deflater(java.util.zip.Deflater) Element(org.w3c.dom.Element) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 62 with DeflaterOutputStream

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);
        }
    }
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) BasicSerialization.writeString(com.google.gerrit.server.ioutil.BasicSerialization.writeString) BasicSerialization.readString(com.google.gerrit.server.ioutil.BasicSerialization.readString)

Example 63 with DeflaterOutputStream

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();
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 64 with DeflaterOutputStream

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;
    }
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 65 with DeflaterOutputStream

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;
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

DeflaterOutputStream (java.util.zip.DeflaterOutputStream)76 ByteArrayOutputStream (java.io.ByteArrayOutputStream)50 Deflater (java.util.zip.Deflater)25 IOException (java.io.IOException)24 OutputStream (java.io.OutputStream)13 InflaterInputStream (java.util.zip.InflaterInputStream)9 DataOutputStream (java.io.DataOutputStream)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BufferedOutputStream (java.io.BufferedOutputStream)3 EOFException (java.io.EOFException)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 ImageException (cbit.image.ImageException)2 DeflateCompressor (com.linkedin.r2.filter.compression.streaming.DeflateCompressor)2 StreamingCompressor (com.linkedin.r2.filter.compression.streaming.StreamingCompressor)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 PipedInputStream (java.io.PipedInputStream)2