BufferedReader and Sockets in java


Suppose I'm using a Socket InputStream like this,in order to read the following data:
(first part encoded in ASCII)

    the rest of this message is binaryCRLF


InputStreamReader isr = new InputStreamReader(socket.getInputStream());
BufferedReader in = new BufferedReader(isr);
String line = in.readLine();

what I expect at this point,is that line contains the text:

the rest of this message is binary

Then I would like to use the original socket InputStream:

 InputStream is = socket.getInputStream();

to read the binary part of the message.

Now, what if the BufferedReader has buffered some of the binary data,
this would be a problem because I would miss part of the data.
Am I misssing something ?

In the source of BufferedReader you will see that the default buffer size is 8192. Because of this the call of readLine() will read more than the bytes of the first line into the buffer.

Use a different approach. Buffer the input and read it twice.