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 to zstd. #4094

Merged
merged 1 commit into from
May 29, 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 @@ -459,7 +459,7 @@ dependencies {
implementation 'com.google.guava:guava:31.0.1-jre'
// compression of messages between client and server
implementation 'org.apache.commons:commons-compress:1.22'
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 @@ -26,8 +26,8 @@
import net.rptools.clientserver.ActivityListener;
import net.rptools.clientserver.ActivityListener.Direction;
import net.rptools.clientserver.ActivityListener.State;
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 @@ -84,7 +84,7 @@ public synchronized void addMessage(Object channel, byte[] message) {
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();

Expand All @@ -96,10 +96,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