Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading byte/char from socket inputstream

805937Oct 20 2010 — edited Oct 20 2010
Hey 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.
This post has been answered by EJP on Oct 20 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2010
Added on Oct 20 2010
5 comments
320 views