• 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

StAX getCharacterOffset method help!

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using StAX, I'm trying to write a small progress meter so I know how far along in parsing the XML file I am. (ie 50% of 100% file complete)

In the location class, there is Location.getCharacterOffset() which is supposed to return either a byte or character position. It seems to be returning a character position, and I dont know how to make it return in bytes.

Does anyone know how I can do this? or does anyone know how I could get the total characters in a file without reading through the whole file?

Its a 100 mb file, so I'm trying to be efficient here.

Thanks a lot for any input, or ideas


[ March 19, 2005: Message edited by: Oliver Ng ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This might be a bit far fetched, but...

Would it be feasible to first (before handing the file to the parser) read the first n bytes of the file into a String and make an assumption that the ratio of bytes to characters is statistically constant throughout the file, regardless of the encoding?
 
Oliver Ng
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you've totally lost me there, could you clarify please?
reply
    Bookmark Topic Watch Topic
  • New Topic