我试图将一个 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;
}
最佳答案
SIPDialog 类没有覆盖 equals 方法,这就是比较失败的原因。请在 jain sip 中打开一个问题 http://java.net/jira/browse/JSIP
关于java - 序列化/反序列化 SIPDIalog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12941092/