switch (st) {
case CHUNK_CRLF:
this.buffer.clear();
final int bytesRead1 = this.in.readLine(this.buffer);
if (bytesRead1 == -1) {
throw new MalformedChunkCodingException(
"CRLF expected at end of chunk");
}
if (!this.buffer.isEmpty()) {
throw new MalformedChunkCodingException(
"Unexpected content at the end of chunk");
}
state = CHUNK_LEN;
//$FALL-THROUGH$
case CHUNK_LEN:
this.buffer.clear();
final int bytesRead2 = this.in.readLine(this.buffer);
if (bytesRead2 == -1) {
throw new ConnectionClosedException("Premature end of chunk coded message body: " +
"closing chunk expected");
}
int separator = this.buffer.indexOf(';');
if (separator < 0) {
separator = this.buffer.length();
}
try {
return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
} catch (final NumberFormatException e) {
throw new MalformedChunkCodingException("Bad chunk header");
}
default:
throw new IllegalStateException("Inconsistent codec state");
}
}