mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 17:58:01 +00:00
add old de/serialization for android 7.1 and below
This commit is contained in:
@@ -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,16 +27,30 @@ public class CustomObjectDecoder extends LengthFieldBasedFrameDecoder {
|
||||
if (frame == null) {
|
||||
return null;
|
||||
} else {
|
||||
ElsaObjectInputStream ois = new ElsaObjectInputStream(new ByteBufInputStream(frame, true));
|
||||
if (GuiBase.getpropertyConfig()){
|
||||
ElsaObjectInputStream ois = new ElsaObjectInputStream(new ByteBufInputStream(frame, true));
|
||||
|
||||
Object var5;
|
||||
try {
|
||||
var5 = ois.readObject();
|
||||
} finally {
|
||||
ois.close();
|
||||
Object var5;
|
||||
try {
|
||||
var5 = ois.readObject();
|
||||
} finally {
|
||||
ois.close();
|
||||
}
|
||||
|
||||
return var5;
|
||||
}
|
||||
else {
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(frame, true));
|
||||
|
||||
return var5;
|
||||
Object var5;
|
||||
try {
|
||||
var5 = ois.readObject();
|
||||
} finally {
|
||||
ois.close();
|
||||
}
|
||||
|
||||
return var5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,21 +20,36 @@ public class CustomObjectEncoder extends MessageToByteEncoder<Serializable> {
|
||||
int startIdx = out.writerIndex();
|
||||
ByteBufOutputStream bout = new ByteBufOutputStream(out);
|
||||
ElsaObjectOutputStream oout = null;
|
||||
ObjectOutputStream ooutOld = null;
|
||||
|
||||
try {
|
||||
bout.write(LENGTH_PLACEHOLDER);
|
||||
oout = new ElsaObjectOutputStream(bout);
|
||||
oout.writeObject(msg);
|
||||
oout.flush();
|
||||
} finally {
|
||||
if (oout != null) {
|
||||
oout.close();
|
||||
} else {
|
||||
bout.close();
|
||||
if (GuiBase.getpropertyConfig()){
|
||||
try {
|
||||
bout.write(LENGTH_PLACEHOLDER);
|
||||
oout = new ElsaObjectOutputStream(bout);
|
||||
oout.writeObject(msg);
|
||||
oout.flush();
|
||||
} finally {
|
||||
if (oout != null) {
|
||||
oout.close();
|
||||
} 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user