Re: [問題] ObjectOutputStream + ImageIO 出現的問題
: ◆ From: 220.132.160.117
: ※ 編輯: tkcn 來自: 220.132.160.117 (12/30 22:21)
: → tkcn:code 更新了,剛剛建立 Stream 的順序錯誤,會導致 deadlock 12/30 22:22
: 推 ogamenewbie:ImageIO.read(in)改成(BufferedImage)in.readObject() 12/31 08:32
: → ogamenewbie:試試看? 12/31 08:33
: → tkcn:BufferedImage 應該不能 Serialize 吧? 12/31 08:48
: 推 ogamenewbie:我試試看弄個 class imp ser 存ImageIO write的byte[] 12/31 09:58
: 推 ogamenewbie:http://paste.plurk.com/show/121974/ 試試看? 12/31 10:37
: → ogamenewbie:先說好, 所有意外狀況全部都沒有預防... 12/31 10:38
: → tkcn:這支可以 work, 感謝。 不過還是很好奇為什麼原本的會有問題 12/31 10:46
看了一下 ImageIO.write(OutputStream) 的 source,
這方法會自動產生 ImageOutputStream,
所以真正送出去的 Stream 就變成:
ImageOutputStream -> ObjectOutputStream -> SocketOutputStream
我猜測可能是因為 ImageOutputStream 和 ObjectOutputStream 都有自己的 header,
當第二次在 ObjectOutputStream 上建立 ImageOutputStream 時,
就會寫入那多餘的 16-byte。
這樣也可以說明為什麼不用 ObjectOutputStream 就不會有問題。
---
我剛剛在測試的時候也有試過利用 ByteArrayOutputStream,
不過沒有額外包成一個 class,結果還是失敗。
也有試過直接把 png file 的 data 丟進 ObjectOutputStream,
( png file 當初也是用 ImageIO.write() 寫入的,並且我也在接收方檢查過 header )
結果接收方還是沒辦法用 ImageIO.read() 接下來。
( javax.imageio.IIOException: Unknown row filter type )
可能要晚點再繼續做測試了。 (用跨年夜測 = =)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.183.199
※ 編輯: tkcn 來自: 140.122.183.199 (12/31 11:20)
推
12/31 12:00, , 1F
12/31 12:00, 1F
推
12/31 16:42, , 2F
12/31 16:42, 2F
→
12/31 16:50, , 3F
12/31 16:50, 3F
→
12/31 17:06, , 4F
12/31 17:06, 4F
推
01/01 08:36, , 5F
01/01 08:36, 5F
→
01/01 11:19, , 6F
01/01 11:19, 6F
推
01/01 22:02, , 7F
01/01 22:02, 7F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 7 篇):