* The size parameter indicates the expected size of the response;
* the actual size can be different. Returns an InputStream to the
* response bytes.
*/
private InputStream readMultilineResponse(int size) throws IOException {
SharedByteArrayOutputStream buf = new SharedByteArrayOutputStream(size);
int b, lastb = '\n';
try {
while ((b = input.read()) >= 0) {
if (lastb == '\n' && b == '.') {
if (debug && !traceSuspended)
out.write(b);
b = input.read();
if (b == '\r') {
if (debug && !traceSuspended)
out.write(b);
// end of response, consume LF as well
b = input.read();
if (debug && !traceSuspended)
out.write(b);
break;
}
}
buf.write(b);
if (debug && !traceSuspended)
out.write(b);
lastb = b;
}
} catch (InterruptedIOException iioex) {
/*
* As above in readResponse, close the socket to recover.
*/
try {
socket.close();
} catch (IOException cex) { }
throw iioex;
}
if (b < 0)
throw new EOFException("EOF on socket");
return buf.toStream();
}