Any way to set/get position of the reader?

408 views
Skip to first unread message

Philippe Proulx

unread,
Jun 20, 2012, 5:29:22 PM6/20/12
to googl...@googlegroups.com
Hi. I am trying to use Gson to read big JSON files. Suppose I have this:

{
  thing: { huge object here },
  something: { huge object here },
  somethingElse: 23
}

I want to use the JsonReader to stream the file. I need the "somethingElse" node first, so I need to skip over "thing" and "something", but then come back to the beggining of "something" to read it.

Is there any way to get a Reader (which JsonReader needs) that features random access of a file?

Thank you.

Jesse Wilson

unread,
Jun 21, 2012, 3:48:38 AM6/21/12
to googl...@googlegroups.com
There's no mark/reset functionality in JsonReader, which is what you'd need to accomplish this. But you probably don't need it. You can do something simpler: just read the whole thing twice. Calling skipValue() after reading the 'thing' key will be fast; the skip method is very fast!
Reply all
Reply to author
Forward
0 new messages