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

View File

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