public int doWrite(ByteChunk chunk,
Response res) throws IOException {
if (!response.isCommitted()) {
// Validate and write response headers
try {
prepareResponse();
} catch (IOException e) {
// Set error flag
error = true;
}
}
int len = chunk.getLength();
// 4 - hardcoded, byte[] marshalling overhead
int chunkSize = Constants.MAX_SEND_SIZE;
int off = 0;
while (len > 0) {
int thisTime = len;
if (thisTime > chunkSize) {
thisTime = chunkSize;
}
len -= thisTime;
responseHeaderMessage.reset();
responseHeaderMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK);
responseHeaderMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime);
responseHeaderMessage.end();
output.write(responseHeaderMessage.getBuffer(), 0, responseHeaderMessage.getLen());
off += thisTime;
}
return chunk.getLength();
}
|