}
public HttpMessage parse() throws IOException, HttpException {
while (this.state != COMPLETED) {
if (this.lineBuf == null) {
this.lineBuf = new CharArrayBuffer(64);
} else {
this.lineBuf.clear();
}
boolean lineComplete = this.sessionBuffer.readLine(this.lineBuf, this.endOfStream);
if (this.maxLineLen > 0 &&
(this.lineBuf.length() > this.maxLineLen ||
(!lineComplete && this.sessionBuffer.length() > this.maxLineLen))) {
throw new IOException("Maximum line length limit exceeded");
}
if (!lineComplete) {
break;
}
switch (this.state) {
case READ_HEAD_LINE:
try {
parseHeadLine();
} catch (ParseException px) {
throw new ProtocolException(px.getMessage(), px);
}
this.state = READ_HEADERS;
break;
case READ_HEADERS:
if (this.lineBuf.length() > 0) {
if (this.maxHeaderCount > 0 && headerBufs.size() >= this.maxHeaderCount) {
throw new IOException("Maximum header count exceeded");
}
parseHeader();
} else {
this.state = COMPLETED;
}
break;
}
if (this.endOfStream && !this.sessionBuffer.hasData()) {
this.state = COMPLETED;
}
}
if (this.state == COMPLETED) {
for (int i = 0; i < this.headerBufs.size(); i++) {
CharArrayBuffer buffer = this.headerBufs.get(i);
try {
this.message.addHeader(lineParser.parseHeader(buffer));
} catch (ParseException ex) {
throw new ProtocolException(ex.getMessage(), ex);
}