Marking and Resetting

It's often useful to be able to read a few bytes, and then back up and reread them. For example, in the design of a Java compiler you don't know for sure whether you've read <, <<, or <<= until you've read one two many characters. It would be useful to be able to back up and reread the token once you know which token you've read. Compiler design and other parsing problems provide many more examples, but this need occurs elsewhere as well.

Some but not all input streams allow you to mark a particular position in the stream, and then return to it. There are three methods that allow this:

 public synchronized void mark(int readlimit)
 public synchronized void reset() throws IOException
 public boolean markSupported()

Copyright 2000 Elliotte Rusty Harold
Last Modified January 28, 2000