• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How keep track of buffer size while parsing?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic