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;
}
}
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);
}
}
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();
}
}
Aggregations