Reputation: 205
I use Jackson for parsing JSON files. The file is passed as a stream to Jackson to create a parser. Here is the sample code :
JsonFactory f = new JsonFactory();
JsonParser parser = f.createParser(inputStream);
I know that createParser() prefetch data from stream into an input buffer. Subsequent call to nextToken() is served from this inputBuffer. In my application, along with parsing, I also want to keep track of the file offset of the inputStream until which I have consumed the data. Due to this buffering, offset tracking does not work.
Does anyone know if there is a way to disable buffering in Jackson? Or, is there an API call that I can use to determine if the buffer has data that has not yet been consumed?
Upvotes: 3
Views: 1398
Reputation: 18803
Why not use JsonParser.getTokenLocation()
or JsonParser.getCurrentLocation()
to keep track of the file offset?
The returned object seems to have the byte position (in addition to the character position), which should be to position in the underlying input stream...
Upvotes: 4