aspose file tools*
The moose likes Performance and the fly likes sending xml records to sax parser using buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "sending xml records to sax parser using buffer " Watch "sending xml records to sax parser using buffer " New topic
Author

sending xml records to sax parser using buffer

karthick sambanghi
Greenhorn

Joined: Sep 25, 2013
Posts: 17
i am having a below piece of code in my worker thread. In my output i am getting xml records from the database.

I'm sending this output to a input stream & finally to a sax parser.

My query is, before sending to the parser i need to store the input stream in buffer. The buffer should store 1000 records. For every 1000 records the parser should be called from buffer.



Waiting for your positive reply.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11411
    
  16

I'm sorry, but I don't see an actual question here...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
karthick sambanghi
Greenhorn

Joined: Sep 25, 2013
Posts: 17
fred rosenberger wrote:I'm sorry, but I don't see an actual question here...


Hi fred rosenberger,

Thanks for your reply and sorry for this.

is there any other possibilities of storing the input stream in buffer and then sending to parser when it reaches the size to 1000 counts(threshold level).

For every thousand count the parser should be called instead of sending the whole records(bulk size).

If so please assist how to store the input stream in buffer for every thousand records.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
I suspect the various "Piped" streams in the java.io package would make your life easier.

If the SAX parser is reading from a piped input stream in one Thread - you can periodically add records to the matching piped output stream in another Thread and coordination will be automatic.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

If it were me I would write a subclass of FilterReader which wrapped that ResultSet, or whatever it is where the XML comes from. If I understand it correctly, the simplest thing you can do is to just override the read() method which returns the next character, and let FilterReader take care of the rest.

And I'm a bit surprised that processing every record and processing the concatenation of exactly 1000 records are equally acceptable, since the parser expects to receive a complete XML document. If each record is a complete XML document then the concatenation of 1000 records cannot be a complete XML document.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
since the parser expects to receive a complete XML document.


Well, to be picky, the SAX parser only requires a stream that starts correctly for an XML document. It will generate SAX events as long as it gets a correctly formatted character stream. In many applications one would quit parsing once you found the right data. Hitting the end of the stream without the closing root element just causes an exception you should handle.

Bill

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sending xml records to sax parser using buffer