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.constraints.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();
}
try {
final String s = this.lineBuf.substringTrimmed(0, separator);
this.chunkSize = Integer.parseInt(s, 16);
} catch (final NumberFormatException e) {
throw new MalformedChunkCodingException("Bad chunk header");
}
this.pos = 0;
} else if (this.endOfStream) {
throw new ConnectionClosedException("Premature end of chunk coded message body: " +
"closing chunk expected");