Re: XML document利用tcp socket來傳遞

看板java作者時間19年前 (2006/05/18 17:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
【 在 Julian (不喜歡臺中) 的大作中提到: 】 : 我想要將利用jdom所產生的xml document直接利用socket來傳遞 : 可是我試了許多方法都不可行 : 因為XML parser好像讀到eof就會關閉 : jdom也只提供將document轉為outputstream的方法 : 不知道大家是否有遇過這樣的問題 : 麻煩大家了 http://www.jdom.org/docs/faq.html#a0340 Why does passing a document through a socket sometimes hang the parser? The problem is that several XML parsers close the input stream when they read E OF (-1). This is true of Xerces, which is JDOM's default parser. It is also tru e of Crimson. Unfortunately, closing a SocketInputStream closes the underlying SocketImpl, setting the file descriptor to null. The socket's output stream is useless after this, so your application will be unable to send a response. To w orkaround, protect your socket's input stream with an InputStream wrapper that doesn't close the underlying stream (override the close() method), or read ever ything into a buffer before handing off to the JDOM builder: byte[] buf = new byte[length]; new DataInputStream(inputStream).readFully(buf); InputStream in = new ByteArrayInputStream(buf); (Contributed by Joseph Bowbeer) -- ※ 來源:‧資訊傳奇 inf.csie.thu.edu.tw‧[FROM: mail.csie.thu.edu.tw]
文章代碼(AID): #14R3yN00 (java)
討論串 (同標題文章)
文章代碼(AID): #14R3yN00 (java)