[jdom-interest] reading xml from a socket

Ken Rune Helland kenh at csc.no
Tue May 15 07:08:16 PDT 2001


How about subclassing java.io.FilterInputStream to decide
when one document is finished and send a EOF to the builder.

Some quasicode:

MyEndofDocumentDectorInputStream is =
         new MyEndofDocumentDectorInputStream(socket.getInputstream());

while(
         is.HasMoreDocuments() // decides if there is more documents in the 
stream
)
{
         is.SendNext() // tell is to stop sendig EOF and send next doc in 
stream.
         Document doc = builder.build(is);
         handleDoc(doc);
}


Shoud be possible, no?


KenR


At 07:34 AM 5/15/2001 -0500, philip.nelson at omniresources.com wrote:
>I'm pretty sure that the inputstream must close for the build to end.  It
>won't have anything to do with the content arriving on the inputstream.  As
>a result, the parser will se the second root element and blow up because the
>document is not well formed.  You will probably need to write your own
>inputstream inplementation if the socket is going to stay open or perhaps
>you could buffer and then call successive builds from a byte array or
>somesuch.
>
> > -----Original Message-----
> > From: Jef Dodson [mailto:jcdodson at hotmail.com]
> > Sent: Monday, May 14, 2001 8:23 PM
> > To: jdom-interest at jdom.org
> > Subject: [jdom-interest] reading xml from a socket
> >
> >
> > Hello,
> > I want to write some code that reads xml from a tcp/ip
> > socket.  The problem
> > is, what if the application on the other end of the socket
> > writes more than
> > one document to the socket's outputstream before my
> > application reads the
> > document from the inputstream?  Will the build() method be
> > smart enough to
> > build each document separately, or will it throw an exception
> > because it
> > looks like the document is not well formed?  For example,
> > suppose a client
> > sends two messages to a server in rapid succession before the
> > server app.
> > reads the data from the socket, so that the xml looks like
> > the following to
> > the server:
> >
> >
> > <message id="1">
> >     <type>text</type>
> >     <body>Hello World</body>
> > </message>
> > <message id="2">
> >     <type>text</type>
> >     <body>Hello again</body>
> > </message>
> >
> > Now, what happens when the builder.build() method is called?
> >
> > Thanks.
> >
> > Jef
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at http://explorer.msn.com
> >
> > _______________________________________________
> > To control your jdom-interest membership:
> > http://lists.denveronline.net/mailman/options/jdom-interest/yo
>uraddr at yourhost.com
>_______________________________________________
>To control your jdom-interest membership:
>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list