I use BufferedReader to read a byte stream (UTF-8 text) in turn. For a certain reason, I need to know exactly where in the byte stream the string begins.
Problem: I canβt use the position of the InputStream I can connect to the BufferedReader, because ... are the reader buffers and reads more lines at a time.
My question is: How to determine the exact byte offset of each line?
One obvious (but incorrect) solution would be to use (line + "\ n"). getBytes ("UTF-8"). There are two problems with this approach: 1) just to count the number of bytes, this is pretty overhead to convert the string back to bytes and 2) the newline string is not always marked as "\ n" - it can also be "\ r \ n "etc.
Are there any other solutions for this?
EDIT: every class similar to LineReader that I have seen so far seems to be buffered. Does anyone know about the unbuffered LineReader class?
source share