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;
if (outputBuffer.position() + thisTime +
Constants.H_SIZE + 4 > outputBuffer.capacity()) {
flush();
}
outputBuffer.put((byte) 0x41);
outputBuffer.put((byte) 0x42);
outputBuffer.putShort((short) (thisTime + 4));
outputBuffer.put(Constants.JK_AJP13_SEND_BODY_CHUNK);
outputBuffer.putShort((short) thisTime);
outputBuffer.put(chunk.getBytes(), chunk.getOffset() + off, thisTime);
outputBuffer.put((byte) 0x00);
off += thisTime;
}
return chunk.getLength();
}
|