Bad news: this is probably all unnecessary. You can do this with BufferedInputStream, which has mark() and reset() methods that take care of rewinding.