int i = cursor.getPos();
// long enough for "HTTP/1.1"?
if (i + protolength + 4 > indexTo) {
throw new ParseException
("Not a valid protocol version: " +
buffer.substring(indexFrom, indexTo));
}
// check the protocol name and slash
boolean ok = true;
for (int j=0; ok && (j<protolength); j++) {
ok = (buffer.charAt(i+j) == protoname.charAt(j));
}
if (ok) {
ok = (buffer.charAt(i+protolength) == '/');
}
if (!ok) {
throw new ParseException
("Not a valid protocol version: " +
buffer.substring(indexFrom, indexTo));
}
i += protolength+1;
int period = buffer.indexOf('.', i, indexTo);
if (period == -1) {
throw new ParseException
("Invalid protocol version number: " +
buffer.substring(indexFrom, indexTo));
}
int major;
try {
major = Integer.parseInt(buffer.substringTrimmed(i, period));
} catch (NumberFormatException e) {
throw new ParseException
("Invalid protocol major version number: " +
buffer.substring(indexFrom, indexTo));
}
i = period + 1;
int blank = buffer.indexOf(' ', i, indexTo);
if (blank == -1) {
blank = indexTo;
}
int minor;
try {
minor = Integer.parseInt(buffer.substringTrimmed(i, blank));
} catch (NumberFormatException e) {
throw new ParseException(
"Invalid protocol minor version number: " +
buffer.substring(indexFrom, indexTo));
}
cursor.updatePos(blank);