Skip to content

Commit

Permalink
server: fixed broken work on network's non-compress mode (-Dxmage.net…
Browse files Browse the repository at this point in the history
…work.nocompress)
  • Loading branch information
JayDi85 committed Sep 18, 2023
1 parent 666c03e commit 9b634d4
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions Mage.Common/src/main/java/mage/utils/CompressUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,31 @@
import mage.remote.traffic.ZippedObjectImpl;

/**
* Helps to compress and decompress data if needed.
* Helps to compress and decompress network data
*
* @author ayrat
*/
public final class CompressUtil {

/**
* Defines should data be compressed or not. True by default. Read from
* system property:
*/
private static boolean compressData;

/**
* Defines the system property name to disable any compressing.
*/
private static final String NO_COMPRESS_DATA_PROPERTY = "nocompress";
// disable data compression in client-server traffic, add java param like -Dxmage.network.nocompress
private static final String NO_COMPRESS_DATA_PROPERTY = "xmage.network.nocompress";
private static final boolean compressData;

static {
compressData = System.getProperty(NO_COMPRESS_DATA_PROPERTY) == null;
}

/**
* Hidden constructor
*/
private CompressUtil() {
}

/**
* Decompress data, but only if it was compressed previously return original
* object otherwise.
*
* @param data Data to decompress
* @return Decompressed object
*/
public static Object decompress(Object data) {
if (!(data instanceof ZippedObject)) {
return data;
}
return ((ZippedObject) data).unzip();
}

/**
* Compress data.
*
* @param data Data to compress
* @return Compressed object
*/
public static Object compress(Object data) {
if (data != null && compressData) {
return new ZippedObjectImpl<>(data);
}
return null;
return data;
}
}

0 comments on commit 9b634d4

Please sign in to comment.