add old de/serialization for android 7.1 and below

This commit is contained in:
Anthony Calosa
2019-11-01 15:03:30 +08:00
parent 31182289b7
commit a5b65eaaed
2 changed files with 53 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
package forge.net;
import forge.GuiBase;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.channel.ChannelHandlerContext;
@@ -7,6 +8,8 @@ import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.serialization.ClassResolver;
import org.mapdb.elsa.ElsaObjectInputStream;
import java.io.ObjectInputStream;
public class CustomObjectDecoder extends LengthFieldBasedFrameDecoder {
private final ClassResolver classResolver;
@@ -24,6 +27,7 @@ public class CustomObjectDecoder extends LengthFieldBasedFrameDecoder {
if (frame == null) {
return null;
} else {
if (GuiBase.getpropertyConfig()){
ElsaObjectInputStream ois = new ElsaObjectInputStream(new ByteBufInputStream(frame, true));
Object var5;
@@ -35,6 +39,19 @@ public class CustomObjectDecoder extends LengthFieldBasedFrameDecoder {
return var5;
}
else {
ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(frame, true));
Object var5;
try {
var5 = ois.readObject();
} finally {
ois.close();
}
return var5;
}
}
}
public static int maxObjectsize = 10000000; //10megabyte???

View File

@@ -1,11 +1,13 @@
package forge.net;
import forge.GuiBase;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.mapdb.elsa.ElsaObjectOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class CustomObjectEncoder extends MessageToByteEncoder<Serializable> {
@@ -18,7 +20,9 @@ public class CustomObjectEncoder extends MessageToByteEncoder<Serializable> {
int startIdx = out.writerIndex();
ByteBufOutputStream bout = new ByteBufOutputStream(out);
ElsaObjectOutputStream oout = null;
ObjectOutputStream ooutOld = null;
if (GuiBase.getpropertyConfig()){
try {
bout.write(LENGTH_PLACEHOLDER);
oout = new ElsaObjectOutputStream(bout);
@@ -30,9 +34,22 @@ public class CustomObjectEncoder extends MessageToByteEncoder<Serializable> {
} else {
bout.close();
}
}
}
else {
try {
bout.write(LENGTH_PLACEHOLDER);
ooutOld = new ObjectOutputStream(bout);
ooutOld.writeObject(msg);
ooutOld.flush();
} finally {
if (ooutOld != null) {
ooutOld.close();
} else {
bout.close();
}
}
}
int endIdx = out.writerIndex();
out.setInt(startIdx, endIdx - startIdx - 4);
}