I'm playing with bencoding and i would like to keep bencoded strings as java strings but they contain binary data blindly converting them to string will corrupt the data. What i am trying to accomplish is have a conversion function that will keep the ascii bytes as ascii end encode non ascii chars in a reversible way.
I have found some examples of what i am trying to accomplish in python but i don't know enough ptyhon to dig through them. this decoder does exactly what i would like to do ascii parts of the torrent stay as ascii but sha1 hashes are printed as "\xd8r\xe7". With my very limited python knowledge he doesn't seem to be doing anything special to the string is this handled by the python interpreter? Can i accomplish the same in Java?
I have played with some encodings such as Base64 or using Integer.toHexString but i get non readable ascii strings in the end?
I have also found a scheme example that prints everything but the sha1 hashes.