I need to write a function that takes in some kind of input stream thing (e.g. an InputStream or a FileChannel) in order to read a large file in two passes: once to precompu
PushbackInputStream will also work, as long as you know how many characters you want to be able to rewind
RandomAccessFile is what you want:
BufferedInputStream
has mark(readlimit)
and reset()
.
readlimit
should be larger than filesize
to make mark valid.
file.length()+1
is OK.
This means mark is valid until readlimit
bytes are read, thus you can go back by reset()
.