Search in sources :

Example 66 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project poi by apache.

the class EscherMetafileBlip method setPictureData.

@Override
public void setPictureData(byte[] pictureData) {
    super.setPictureData(pictureData);
    setUncompressedSize(pictureData.length);
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DeflaterOutputStream dos = new DeflaterOutputStream(bos);
        dos.write(pictureData);
        dos.close();
        raw_pictureData = bos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException("Can't compress metafile picture data", e);
    }
    setCompressedSize(raw_pictureData.length);
    setCompressed(true);
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 67 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project voltdb by VoltDB.

the class ScriptWriterZipped method openFile.

protected void openFile() {
    try {
        FileAccess fa = database.getFileAccess();
        java.io.OutputStream fos = fa.openOutputStreamElement(outFile);
        outDescriptor = fa.getFileSync(fos);
        fileStreamOut = new DeflaterOutputStream(fos, new Deflater(Deflater.DEFAULT_COMPRESSION), bufferSize);
    } catch (IOException e) {
        throw Error.error(ErrorCode.FILE_IO_ERROR, ErrorCode.M_Message_Pair, new Object[] { e.toString(), outFile });
    }
}
Also used : Deflater(java.util.zip.Deflater) FileAccess(org.hsqldb_voltpatches.lib.FileAccess) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) IOException(java.io.IOException)

Example 68 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project jdk8u_jdk by JetBrains.

the class PNGImageWriter method deflate.

private byte[] deflate(byte[] b) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(baos);
    dos.write(b);
    dos.close();
    return baos.toByteArray();
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 69 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project simba-os by cegeka.

the class SAMLServiceImpl method encodeSAMLRequest.

protected String encodeSAMLRequest(byte[] pSAMLRequest) throws RuntimeException {
    Base64 base64Encoder = new Base64();
    try {
        ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
        Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
        DeflaterOutputStream def = new DeflaterOutputStream(byteArray, deflater);
        def.write(pSAMLRequest);
        def.close();
        byteArray.close();
        String stream = new String(base64Encoder.encode(byteArray.toByteArray()));
        return stream.trim();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) Deflater(java.util.zip.Deflater) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 70 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project ddf by codice.

the class SimpleSignTest method deflateAndBase64Encode.

/**
     * Deflates a value and Base64 encodes the result. This code is copied from RestSecurity because it would cause a circular dependency to use it directly..
     *
     * @param value value to deflate and Base64 encode
     * @return String
     * @throws IOException if the value cannot be converted
     */
public static String deflateAndBase64Encode(String value) throws IOException {
    ByteArrayOutputStream valueBytes = new ByteArrayOutputStream();
    try (OutputStream tokenStream = new DeflaterOutputStream(valueBytes, new Deflater(Deflater.DEFLATED, true))) {
        tokenStream.write(value.getBytes(StandardCharsets.UTF_8));
        tokenStream.close();
        return Base64.getEncoder().encodeToString(valueBytes.toByteArray());
    }
}
Also used : Deflater(java.util.zip.Deflater) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) OutputStream(java.io.OutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

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