• Post Reply Bookmark Topic Watch Topic
  • New Topic

How keep track of buffer size while parsing?  RSS feed

 
Phil Weinstein
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working on parsing a tab delimited file and converting it to an xml stringbuffer, which I am going to then put on a queue. I have a requirement from my architect that I am supposed to keep track of how big the buffer is getting and if hits a certain size I am supposed to create new buffer and put the old one on the queue and so on.
My first question is - how do I even keep track of the size - this may not be a too difficult but I have never done anything like this so I have no idea how?
Secondly, wouldn't a better approach be to just somehow break my incoming tab delimited file up first and then just parse those chunks - as my parsing routine is already quite complex plus I think the performance is going to be bad - if I constantly have to check how big the buffer is getting, while I am parsing.
If anybody has any ideas on this I would greatly appreciate it.
Many Thanks!
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first question is - how do I even keep track of the size - this may not be a too difficult but I have never done anything like this so I have no idea how?
StringBuffer class has a method length(), -- returns the length (character count) of the string buffer. Is that what you are looking for?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you may be getting into a tricky place ... splitting XML messages into multiple queue entries. Do they have to split on tag boundaries, row boundaries, or can you just split at exactly max buffer length regardless of where it falls in the XML? Will the receiving end know how to distinguish fragments from complete messages, and put fragments back together? Hope you have clear specs there!
To split on complete tags, your code might look something like:

where nextTag is a whole tag: <thing>value</thing>
 
Gerald Luckenbill
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for the responses:
To clarify - regarding the size:
Well what I am really after is the bytes - preferably I would like some api which would return bytes - but if that does not exist I guess I could convert the chars to bytes and thus compute my size in btyes - does anyone know what that algorithm is - to convert chars to bytes - is it something like a char = 2 bytes, or a char = 4 bytes?

And to clariy where to break the xml:
I have a specified tag that I have to break on. If I go over the max size a bit till I come to the specified tag that is okay.
Many Thanks!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!