I'm trying to write a class that reads HTTP requests and responses and parses them. Since the headers are ordinary text it seemed easiest to read them using a BufferedReader and the readLine method. This obviously won't do for the data body as it may be binary, so I want to switch over to read raw bytes after the headers have been read.
Right now, I'm doing something like this:
InputStream input=socket.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(input));
BufferedInputStream binstream=new BufferedInputStream(input);
The problem is that the BufferedReader is reading ahead and gobbling up all the binary data from the stream before I have a chance to get at it with the binstream.
Is there a way to prevent it from reading beyond the newline for each call to readLine? Or is there a better way to read single lines of ASCII text followed raw binary data?