String statusMsg = tokens.nextToken("\n\r");
final int code;
try {
code = Integer.parseInt(statusCode);
} catch (NumberFormatException e) {
throw new XmlRpcClientException("Server returned invalid status code: "
+ statusCode + " " + statusMsg, null);
}
if (code < 200 || code > 299) {
throw new XmlRpcHttpTransportException(code, statusMsg);
}
int contentLength = -1;
for (;;) {
line = HttpUtil.readLine(input, buffer);
if (line == null || "".equals(line)) {
break;
}
line = line.toLowerCase();
if (line.startsWith("content-length:")) {
contentLength = Integer.parseInt(line.substring("content-length:".length()).trim());
} else if (line.startsWith("content-encoding:")) {
responseGzipCompressed = HttpUtil.isUsingGzipEncoding(line.substring("content-encoding:".length()));
}
}
InputStream result;
if (contentLength == -1) {
result = input;
} else {
result = new LimitedInputStream(input, contentLength);
}
return result;
} catch (IOException e) {
throw new XmlRpcClientException("Failed to read server response: " + e.getMessage(), e);
}
}