Search in sources :

Example 1 with ZOutputStream

use of com.jcraft.jzlib.ZOutputStream in project Openfire by igniterealtime.

the class SocketConnection method startCompression.

@Override
public void startCompression() {
    compressed = true;
    try {
        if (tlsStreamHandler == null) {
            ZOutputStream out = new ZOutputStream(ServerTrafficCounter.wrapOutputStream(socket.getOutputStream()), JZlib.Z_BEST_COMPRESSION);
            out.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
            writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
            xmlSerializer = new XMLSocketWriter(writer, this);
        } else {
            ZOutputStream out = new ZOutputStream(tlsStreamHandler.getOutputStream(), JZlib.Z_BEST_COMPRESSION);
            out.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
            writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
            xmlSerializer = new XMLSocketWriter(writer, this);
        }
    } catch (IOException e) {
        // TODO Would be nice to still be able to throw the exception and not catch it here
        Log.error("Error while starting compression", e);
        compressed = false;
    }
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ZOutputStream(com.jcraft.jzlib.ZOutputStream) BufferedWriter(java.io.BufferedWriter)

Example 2 with ZOutputStream

use of com.jcraft.jzlib.ZOutputStream in project k-9 by k9mail.

the class ImapConnection method enableCompression.

private void enableCompression() throws IOException, MessagingException {
    try {
        executeSimpleCommand(Commands.COMPRESS_DEFLATE);
    } catch (NegativeImapResponseException e) {
        Log.d(LOG_TAG, "Unable to negotiate compression: " + e.getMessage());
        return;
    }
    try {
        InflaterInputStream input = new InflaterInputStream(socket.getInputStream(), new Inflater(true));
        ZOutputStream output = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_SPEED, true);
        output.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
        setUpStreamsAndParser(input, output);
        if (K9MailLib.isDebug()) {
            Log.i(LOG_TAG, "Compression enabled for " + getLogId());
        }
    } catch (IOException e) {
        close();
        Log.e(LOG_TAG, "Error enabling compression", e);
    }
}
Also used : InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) IOException(java.io.IOException) ZOutputStream(com.jcraft.jzlib.ZOutputStream)

Example 3 with ZOutputStream

use of com.jcraft.jzlib.ZOutputStream in project dhis2-core by dhis2.

the class DataStreamSerializer method write.

public static void write(DataStreamSerializable entity, OutputStream out) throws IOException {
    ByteArrayOutputStream baos = serializePersistent(entity);
    ZOutputStream gzip = new ZOutputStream(out, JZlib.Z_BEST_COMPRESSION);
    DataOutputStream dos = new DataOutputStream(gzip);
    try {
        byte[] res = baos.toByteArray();
        dos.write(res);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        dos.flush();
        dos.close();
    //gzip.finish();
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ZOutputStream(com.jcraft.jzlib.ZOutputStream) IOException(java.io.IOException)

Aggregations

ZOutputStream (com.jcraft.jzlib.ZOutputStream)3 IOException (java.io.IOException)3 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Inflater (java.util.zip.Inflater)1 InflaterInputStream (java.util.zip.InflaterInputStream)1