我试图将 gov.nist.javax.sip.stack.SIPDialog 对象序列化和反序列化到 Cassandra 中。但是当我将反序列化对象与我序列化的原始 SIPDialog 对象进行比较时,对反序列化对象的等于比较失败。所以看起来我在序列化中遗漏了一些东西。我正在使用 ByteArraySerializer 将字节读/写到 Cassandra。
//保存对话框
MutationBatch mutationBatch = createMutator();
byte[] dialogBytes = SIPDialogEntity.serializeDialog(dialog);
mutationBatch.withRow(SIPDIALOGS, dialogId)
.putColumn("dialog".getBytes(),dialogBytes,null);
mutationBatch.execute();
public static byte[] serializeDialog(SIPDialog dialog) throws IOException {
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bStream);
oos.writeObject(dialog);
oos.close();
byte[] bytes = bStream.toByteArray();
bStream.close();
return bytes;
}
//阅读对话框
Column<byte[]> result;
result = getKeySpace().prepareQuery(SIPDIALOGS).getKey(dialogId).getColumn("dialog").execute().getResult();
sipDialog = SIPDialogEntity.deserializeDialog(result.getByteArrayValue());
public static SIPDialog deserializeDialog(byte[] byteArrayDialog) throws IOException, ClassNotFoundException {
System.out.println("DEBUG Reading Dialog Bytes:" + byteArrayDialog );
ByteArrayInputStream bStream = new ByteArrayInputStream(byteArrayDialog);
ObjectInputStream ois = new ObjectInputStream(bStream);
SIPDialog dialog = (SIPDialog) ois.readObject();
ois.close();
bStream.close();
return dialog;
}