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