[jdom-interest] Building from Socket
Laurent Bihanic
laurent.bihanic at atosorigin.com
Tue Nov 18 08:18:02 PST 2003
Hi,
Sebastian Robertsson wrote:
> I know this is an old topic - the problem of building a JDOM-doc read from a socket without closing it. I've
> just tried this solution:
>
> http://www.servlets.com/archive/servlet/ReadMsg?msgId=340949&listName=jdom-interest
The code I provided was intended to read data from the InputStream provided by
an HTTP request. This is a very specific input stream because, thanks to the
HTTP protocol, it knows when the data ends.
When using this code directly on a socket input stream, it can't know when a
data chunk (document) is complete. You need to add an application-specific
protocol information around the raw data to let your code know when to stop
reading from the socket.
If your data only contains XML, you could for example send a vertical tab
character (ascii code 11, hex. 0x0B), which is illegal in XML, to mark the end
of a data chunk. (But don't forget to remove it from the data before handing
over to the XML parser.)
Laurent
More information about the jdom-interest
mailing list