in httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java [99:141]
private void readChunkHead() throws IOException {
if (this.lineBuf == null) {
this.lineBuf = new CharArrayBuffer(32);
} else {
this.lineBuf.clear();
}
if (this.endOfChunk) {
if (this.buffer.readLine(this.lineBuf, this.endOfStream)) {
if (!this.lineBuf.isEmpty()) {
throw new MalformedChunkCodingException("CRLF expected at end of chunk");
}
} else {
if (this.buffer.length() > 2 || this.endOfStream) {
throw new MalformedChunkCodingException("CRLF expected at end of chunk");
}
return;
}
this.endOfChunk = false;
}
final boolean lineComplete = this.buffer.readLine(this.lineBuf, this.endOfStream);
final int maxLineLen = this.http1Config.getMaxLineLength();
if (maxLineLen > 0 &&
(this.lineBuf.length() > maxLineLen ||
!lineComplete && this.buffer.length() > maxLineLen)) {
throw new MessageConstraintException("Maximum line length limit exceeded");
}
if (lineComplete) {
int separator = this.lineBuf.indexOf(';');
if (separator < 0) {
separator = this.lineBuf.length();
}
final String s = this.lineBuf.substringTrimmed(0, separator);
try {
this.chunkSize = Long.parseLong(s, 16);
} catch (final NumberFormatException e) {
throw new MalformedChunkCodingException("Bad chunk header: " + s);
}
this.pos = 0L;
} else if (this.endOfStream) {
throw new ConnectionClosedException(
"Premature end of chunk coded message body: closing chunk expected");
}
}