Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sending xml records to sax parser using buffer

 
karthick sambanghi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, but I don't see an actual question here...
 
karthick sambanghi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic