Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change network compression from lzma to zstd. #4083

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ dependencies {
implementation 'com.google.guava:guava:31.1-jre'
// compression of messages between client and server
implementation 'org.apache.commons:commons-compress:1.23.0'
implementation 'org.tukaani:xz:1.9'
implementation 'com.github.luben:zstd-jni:1.5.5-3'
// intellij forms runtime
implementation 'com.jetbrains.intellij.java:java-gui-forms-rt:223.7571.182'
// layout for forms created in code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
*/
package net.rptools.clientserver.simple.connection;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -30,8 +26,8 @@
import net.rptools.clientserver.ActivityListener;
import net.rptools.clientserver.simple.DisconnectHandler;
import net.rptools.clientserver.simple.MessageHandler;
import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream;
import org.apache.commons.compress.compressors.lzma.LZMACompressorOutputStream;
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -61,10 +57,9 @@ private List<byte[]> getOutQueue(Object channel) {
private byte[] compress(byte[] message) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(message.length);
OutputStream ios = new LZMACompressorOutputStream(baos);
OutputStream ios = new ZstdCompressorOutputStream(baos);
ios.write(message);
ios.close();

var compressedMessage = baos.toByteArray();
return compressedMessage;
} catch (IOException e) {
Expand All @@ -73,10 +68,9 @@ private byte[] compress(byte[] message) {
}

private byte[] inflate(byte[] compressedMessage) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(compressedMessage.length);
InputStream bytesIn = new ByteArrayInputStream(compressedMessage);
try {
InputStream ios = new LZMACompressorInputStream(bytesIn);
InputStream ios = new ZstdCompressorInputStream(bytesIn);
var decompressed = ios.readAllBytes();
ios.close();
return decompressed;
Expand Down