Search in sources :

Example 86 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project freeplane by freeplane.

the class Dictionary method save.

/**
 * Save this dictionary to the OutputStream. The data will be compressed. After finish the OutputStream is closed.
 * @param stream the OutputStream
 * @throws IOException if an I/O error occurs.
 */
public void save(final OutputStream stream) throws IOException {
    final Deflater deflater = new Deflater();
    deflater.setLevel(Deflater.BEST_COMPRESSION);
    final DeflaterOutputStream zip = new DeflaterOutputStream(stream, deflater);
    for (int i = 0; i < size; i++) {
        zip.write(tree[i]);
        zip.write(tree[i] >> 8);
    }
    zip.flush();
    zip.close();
}
Also used : Deflater(java.util.zip.Deflater) DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 87 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project navajo by Dexels.

the class JavaNetNavajoClientImpl method postNavajo.

private void postNavajo(Navajo inputNavajo, boolean useCompression, HttpURLConnection con) throws IOException {
    if (useCompression) {
        if (forceGzip) {
            con.setRequestProperty("Content-Encoding", "gzip");
            con.setRequestProperty("Accept-Encoding", "gzip");
        } else {
            con.setChunkedStreamingMode(1024);
            con.setRequestProperty("Transfer-Encoding", "chunked");
            con.setRequestProperty("Content-Encoding", "jzlib");
            con.setRequestProperty("Accept-Encoding", "jzlib");
        }
        BufferedWriter out = null;
        try {
            if (forceGzip) {
                out = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(con.getOutputStream()), StandardCharsets.UTF_8));
            } else {
                out = new BufferedWriter(new OutputStreamWriter(new DeflaterOutputStream(con.getOutputStream()), StandardCharsets.UTF_8));
            }
            inputNavajo.write(out);
        } finally {
            if (out != null) {
                try {
                    out.flush();
                    out.close();
                } catch (IOException e) {
                    logger.error("Error: ", e);
                }
            }
        }
    } else {
        con.setRequestProperty("noCompression", "true");
        try (BufferedWriter os = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), StandardCharsets.UTF_8))) {
            inputNavajo.write(os);
        }
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 88 with DeflaterOutputStream

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

the class FlateFilter method encode.

@Override
protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters) throws IOException {
    int compressionLevel = getCompressionLevel();
    Deflater deflater = new Deflater(compressionLevel);
    try (DeflaterOutputStream out = new DeflaterOutputStream(encoded, deflater)) {
        IOUtils.copy(input, out);
    }
    encoded.flush();
    deflater.end();
}
Also used : Deflater(java.util.zip.Deflater) DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 89 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project jjwt by jwtk.

the class DeflateCompressionCodec method doCompress.

@Override
public byte[] doCompress(byte[] payload) throws IOException {
    Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
    ByteArrayOutputStream outputStream = null;
    DeflaterOutputStream deflaterOutputStream = null;
    try {
        outputStream = new ByteArrayOutputStream();
        deflaterOutputStream = new DeflaterOutputStream(outputStream, deflater, true);
        deflaterOutputStream.write(payload, 0, payload.length);
        deflaterOutputStream.flush();
        return outputStream.toByteArray();
    } finally {
        Objects.nullSafeClose(outputStream, deflaterOutputStream);
    }
}
Also used : Deflater(java.util.zip.Deflater) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 90 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project bigbluebutton by bigbluebutton.

the class ScreenVideoEncoder method encodePixelsSVC2.

public static byte[] encodePixelsSVC2(int[] pixels, int width, int height) {
    changePixelScanFromBottomLeftToTopRight(pixels, width, height);
    if (paletteIndex == null)
        createPaletteIndex();
    try {
        // TODO calibrate initial size
        ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
        for (int i = 0; i < pixels.length; i++) {
            writeAs15_7(pixels[i], baos1);
        }
        // baos2 contains everything from IMAGEBLOCKV2 except the DataSize field
        // TODO calibrate initial size
        ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
        // IMAGEFORMAT:
        // ColorDepth: UB[2] 10 (15/7 hybrid color image); HasDiffBlocks: UB[1] 0; Zlib prime stuff (2 bits) not used (0)
        baos2.write(16);
        // No ImageBlockHeader (IMAGEDIFFPOSITION, IMAGEPRIMEPOSITION)
        Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
        DeflaterOutputStream deflateroutputstream = new DeflaterOutputStream(baos2, deflater);
        deflateroutputstream.write(baos1.toByteArray());
        deflateroutputstream.finish();
        byte[] dataBuffer = baos2.toByteArray();
        // DataSize field
        int dataSize = dataBuffer.length;
        // TODO calibrate initial size
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writeShort(((OutputStream) (baos)), dataSize);
        // Data
        baos.write(dataBuffer, 0, dataSize);
        return baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Deflater(java.util.zip.Deflater) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

DeflaterOutputStream (java.util.zip.DeflaterOutputStream)162 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 Deflater (java.util.zip.Deflater)63 IOException (java.io.IOException)52 OutputStream (java.io.OutputStream)39 DataOutputStream (java.io.DataOutputStream)21 InflaterInputStream (java.util.zip.InflaterInputStream)16 GZIPOutputStream (java.util.zip.GZIPOutputStream)12 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)8 InputStream (java.io.InputStream)7 ObjectOutputStream (java.io.ObjectOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FileInputStream (java.io.FileInputStream)6 BufferedOutputStream (java.io.BufferedOutputStream)5 ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)5 Saml2Exception (org.springframework.security.saml2.Saml2Exception)5 ByteBuffer (java.nio.ByteBuffer)4 EOFException (java.io.EOFException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3