<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.3315.2870" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>In the FAQ,</FONT></DIV>
<DIV><FONT size=2>
<P><FONT face="Arial, Helvetica, sans-serif"><B><FONT color=#003366 size=2>Why
does passing a document through a socket sometimes hang the
parser?</FONT></B></FONT></P>
<P><FONT face="Arial, Helvetica, sans-serif" size=2>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 <FONT
face="Courier New, Courier, mono">SocketInputStream</FONT> closes the underlying
<FONT face="Courier New, Courier, mono">SocketImpl</FONT>, setting the file
descriptor to <FONT face="Courier New, Courier, mono">null</FONT>. 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 <FONT
face="Courier New, Courier, mono">InputStream</FONT> wrapper that doesn't close
the underlying stream (override the <FONT
face="Courier New, Courier, mono">close()</FONT> method), or read everything
into a buffer before handing off to the JDOM builder:</FONT></FONT><FONT
size=2></FONT></P></DIV>
<DIV><FONT size=2>the following method is mentioned,but how can I calculate the
"length"?<BR></DIV></FONT>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2> byte[] buf = new byte[<STRONG><FONT
size=3>length</FONT></STRONG>];<BR> new
DataInputStream(inputStream).readFully(buf);<BR> InputStream
in = new ByteArrayInputStream(buf);<BR> <BR> <BR>
<BR><BR></DIV></FONT></BODY></HTML>