多数のオブジェクトをファイルにシリアル化しようとしています。特に、私が書き込もうとすると
public void execute(PipelineContext context) throws Exception {
FileOutputStream fos = new FileOutputStream("test_audit_trail2.objects");
ObjectOutputStream oos = new ObjectOutputStream(fos);
BigInteger rho = (BigInteger) context.get("rho");
BigInteger p = (BigInteger) context.get("p");
BigInteger xS = (BigInteger) context.get("xs");
BigInteger zSBar = (BigInteger)context.get("zsbar");
int nS = (Integer) context.get("ns");
P2PShuffler ownShuff = (P2PShuffler) context.get("shuffler");
HexCryptor cryptor = (HexCryptor) context.get("cryptor");
String[] PRPrimePrimeBar = (String []) context.get("pr_prime_prime_bar");
P2PAuditTrailGenerator ownATG = (P2PAuditTrailGenerator) context.get("p2p_audit_trail_generator");
int kS = (Integer) context.get("ks");
oos.writeObject(rho);
oos.writeObject(p);
oos.writeObject(xS);
oos.writeObject(zSBar);
oos.writeObject(ownShuff);
oos.writeObject(cryptor);
oos.writeObject(PRPrimePrimeBar);
oos.writeObject(ownATG);
oos.writeObject(nS);
oos.writeObject(kS);
これは問題なく発生し、すべての writeObject が成功し、対応するストリームを忠実に閉じます。しかし、readObject() を呼び出してすべてのオブジェクトを再構築しようとすると、UTFDataFormatException
java.io.UTFDataFormatException
at java.io.ObjectInputStream$BlockDataInputStream.readUTFSpan(ObjectInputStream.java:3081)
at java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(ObjectInputStream.java:3006)
at java.io.ObjectInputStream$BlockDataInputStream.readUTF(ObjectInputStream.java:2819)
at java.io.ObjectInputStream.readUTF(ObjectInputStream.java:1050)
at java.io.ObjectStreamClass.readNonProxy(ObjectStreamClass.java:614)
at java.io.ObjectInputStream.readClassDescriptor(ObjectInputStream.java:808)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1564)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1315)
at java.io.ObjectInputStream.skipCustomData(ObjectInputStream.java:1911)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1873)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at edu.foo.peer.pipeline.AuditTrailCheckStageTest.setUp
readObject
and をwriteObject
1 つずつコメント アウトした後P2PAuditTrailGenerator
、これを除外すると、すべてのオブジェクトを正常に読み込むことができるようです。このクラスを見ると、String関連のオブジェクトがないように見えます。
public class P2PAuditTrailGenerator implements Serializable {
private int num;
private BigInteger phi;
private BigInteger rho;
/**
* @param auditTrailSecretKeys The secret keys used for audit trail
*/
private BigInteger[] auditTrailSecretKeys;
private BigInteger[] encAuditTrails;
private Random rnd;
public BigInteger [] getAuditTrailSecretKeys(){
return auditTrailSecretKeys;
}
public P2PAuditTrailGenerator(int num, BigInteger rho, BigInteger phi) {
this.num = num;
this.phi = phi;
this.rho = rho;
auditTrailSecretKeys = new BigInteger[num];
encAuditTrails = new BigInteger[num];
rnd = new Random();
}
public BigInteger[] generateATs() {
for (int i = 0; i < num; i++) {
//assuming the security parameter is always 512 or 1024;
auditTrailSecretKeys[i] = new BigInteger(200, rnd).mod(phi);
encAuditTrails[i] = rho.modPow(auditTrailSecretKeys[i], phi);
}
return encAuditTrails;
}
}
間違ったクラスを識別していますか、そうでない場合、実装の何が問題になっていますか?