所以我試圖寫出一個對象到一個ByteArray,但由於某種原因,它不寫任何東西,我看到的事實是返回值爲0,讀它會導致一個例外。OutputStream與ByteArrayOutputStream不寫
BAoutput = new ByteArrayOutputStream();
Oout = new ObjectOutputStream(BAoutput);
Oout.writeObject(receiver);
其中receiver
是我通過參數獲得的對象。 的例外始終是相同的:
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
任何想法?
大部分代碼:(有一對夫婦在它上面的定義,沒有什麼有趣的真)
try {
BAoutput = new ByteArrayOutputStream();
Oout = new ObjectOutputStream(BAoutput);
BAinput = new ByteArrayInputStream(BAoutput.toByteArray());
Oin = new ObjectInputStream(BAinput);
Oout.writeObject(receiver);
retval = method.invoke(receiver, args);
for (Method curr: postMethods){
curr.setAccessible(true);
if (curr.invoke(receiver).equals(false)){
receiver = Oin.readObject();
throw new PostconditionFailure();
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
try {
Oin.close();
Oout.close();
BAinput.close();
BAoutput.close();
} catch (IOException e) {
e.printStackTrace();
}
}
您是否刷新/關閉輸出流? – Synesso 2010-05-28 06:27:23
拋出的實際異常是什麼? – 2010-05-28 06:28:10
請添加例外的第一行(例外類型和消息) – 2010-05-28 06:28:37