Hey I could use some help.
I'm extracting data from a file that uses Bencoding. Its a Metainfo .torrent file for a Torrent Client I'm working on. I'm reading it char by char using an InputStreamReader.
The problem is in the middle of the concatenated string file there is a byte string I need to grab. The InputStreamReader only has methods for reading characters.
Is there a way I can convert the character output of the InputStreamReader into the raw bytes from the file?
From the documentation... it says that InputStreamReader will read a random number of bytes for each .read() statement as it tries to find characters. So I'm confused at how I might convert that back into raw bytes that might be outside of the range.
Bellow is the part of the file I want to read.
It's a short clip of the data becuase the forum doesn't like all the special characters the binary shows up as.
pieces1100:à•ì†Á' ...
pieces is the name of the data and 1100 is the number of bytes to be read. It's supposed to be a concatenation of SHA-1 hashes for a file download.
I'm reading each char from the file like this...
int intch; intch = inputStreamReader.read(); //char hold veriable char ch = (char) intch;
I know I can reopen the file with a new reader that reads byte by byte. The problem is I would then have to write code to convert and then search the bytes for the location of the byte string in the middle of the file. With the InputStreamReader I have read up to it's location.