forked from External/mage
server: fixed broken work on network's non-compress mode (-Dxmage.network.nocompress)
This commit is contained in:
parent
666c03e48c
commit
9b634d44c6
1 changed files with 5 additions and 31 deletions
|
|
@ -4,40 +4,20 @@ import mage.remote.traffic.ZippedObject;
|
|||
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;
|
||||
|
|
@ -45,16 +25,10 @@ public final class CompressUtil {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue