Alternatively, you could have a value like `bufferOffset` and start that at 0, then `pos` is the offset into `buffer`. To compute the total number of bytes read it's `bufferOffset + pos`; to compute the next byte to read it's just `pos`. Also, bufferOffset should be a long.