[jdom-interest] A problem about reading xml from socket

alex alexdingdang at hotmail.com
Fri Apr 4 00:23:03 PST 2003


In the FAQ,
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 EOF (-1). This is true of Xerces, which is JDOM's default parser. It is also true 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 workaround, protect your socket's input stream with an InputStream wrapper that doesn't close the underlying stream (override the close() method), or read everything into a buffer before handing off to the JDOM builder:

the following method is mentioned,but how can I calculate the "length"?


    byte[] buf = new byte[length];
    new DataInputStream(inputStream).readFully(buf);
    InputStream in = new ByteArrayInputStream(buf);
 
 
 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030404/494898b2/attachment.htm


More information about the jdom-interest mailing list