I am trying to write a class that reads HTTP requests and responses and parses them. Since the headers are plain text, the easiest way to read them is with the BufferedReader and readLine methods. This will obviously not do for the data body, since it can be binary, so I want to switch to reading raw bytes after reading the headers.
Now I am 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 reads ahead and absorbs all binary data from the stream before I can get to it using the bin stream.
Is there a way to prevent it from reading outside the newline for every call to readLine ? Or is there a better way to read single lines of ASCII text with raw binary data?
download
source share