while (HTTP.isWhitespace(buffer.charAt(i))) {
i++;
}
int blank = buffer.indexOf(' ', i, indexTo);
if (blank <= 0) {
throw new ProtocolException(
"Unable to parse HTTP-Version from the status line: "
+ buffer.substring(indexFrom, indexTo));
}
HttpVersion ver = BasicHttpVersionFormat.parse(buffer, i, blank);
i = blank;
//advance through spaces
while (HTTP.isWhitespace(buffer.charAt(i))) {
i++;
}
//handle the Status-Code
blank = buffer.indexOf(' ', i, indexTo);
if (blank < 0) {
blank = indexTo;
}
int statusCode = 0;
try {
statusCode = Integer.parseInt(buffer.substringTrimmed(i, blank));
} catch (NumberFormatException e) {
throw new ProtocolException(
"Unable to parse status code from status line: "
+ buffer.substring(indexFrom, indexTo));
}
//handle the Reason-Phrase
i = blank;
String reasonPhrase = null;
if (i < indexTo) {
reasonPhrase = buffer.substringTrimmed(i, indexTo);
} else {
reasonPhrase = "";
}
return new BasicStatusLine(ver, statusCode, reasonPhrase);
} catch (IndexOutOfBoundsException e) {
throw new ProtocolException("Invalid status line: " +
buffer.substring(indexFrom, indexTo));
}
}