clockworkgeek
clockworkgeek

Reputation: 37700

Capture byte number/offset for SAXParser

Like in this question I am trying to record the exact position when parsing XML.

I already use the SAX Locator passed to setDocumentLocator() to record the line and column number but that doesn't give the offset from the beginning of the file. Is there a way to find the number of bytes read so far by the SAX parser or offset of each line without re-reading the whole file?

Upvotes: 2

Views: 1334

Answers (2)

clockworkgeek
clockworkgeek

Reputation: 37700

I found another question and answer which suggests using an XMLStreamReader instead of SAXParser because it has getLocation().getCharacterOffset() instead. It already has exactly what I need.

Upvotes: 1

Dmitry Negoda
Dmitry Negoda

Reputation: 3199

Hypothetically, you can use the CountingInputStream from Apache commons IO.

Upvotes: 1

Related Questions