Reading byte/char from socket inputstream
805937Oct 20 2010 — edited Oct 20 2010Hey fellow coders,
I've ran into a bit of problem coding a http client reader for my assignment. I have created simple program that opens a connection with a server and requests for a file to download. The socket inputstream is wrapped in a bufferedreader and I can successfully retrieve the full server text response through the reader. Unfortunately, whenever I download a mp3 file, the data is corrupted. The problem lies in the fact that bufferedreader decodes the byte stream into a string with utf8. I can't use the underlying socket inputstream as bufferedreader has already read ahead into it and may have passed the start of the content field. Parsing the string with getBytes("UTF 8") doesn't work either as the sound file will be corrupted.
My question is, is there any reader that can return me data from a single stream both as char or byte? Has anyone else ran into this problem and found a workaround to it?
Thanks.