FileDocCategorySizeDatePackage
ChunkedOutputFilter.javaAPI DocApache Tomcat 6.0.144857Fri Jul 20 04:20:34 BST 2007org.apache.coyote.http11.filters

ChunkedOutputFilter

public class ChunkedOutputFilter extends Object implements org.apache.coyote.http11.OutputFilter
Chunked output filter.
author
Remy Maucherat

Fields Summary
protected static final String
ENCODING_NAME
protected static final org.apache.tomcat.util.buf.ByteChunk
ENCODING
protected static final org.apache.tomcat.util.buf.ByteChunk
END_CHUNK
End chunk.
protected org.apache.coyote.OutputBuffer
buffer
Next buffer in the pipeline.
protected byte[]
chunkLength
Buffer used for chunk length conversion.
protected org.apache.tomcat.util.buf.ByteChunk
chunkHeader
Chunk header.
Constructors Summary
public ChunkedOutputFilter()
Default constructor.



    // ----------------------------------------------------- Static Initializer


     
        ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length());
        byte[] END_CHUNK_BYTES = {(byte) '0", (byte) '\r", (byte) '\n", 
                                  (byte) '\r", (byte) '\n"};
        END_CHUNK.setBytes(END_CHUNK_BYTES, 0, END_CHUNK_BYTES.length);
    
        chunkLength = new byte[10];
        chunkLength[8] = (byte) '\r";
        chunkLength[9] = (byte) '\n";
    
Methods Summary
public intdoWrite(org.apache.tomcat.util.buf.ByteChunk chunk, org.apache.coyote.Response res)
Write some bytes.

return
number of bytes written by the filter



    // ------------------------------------------------------------- Properties


    // --------------------------------------------------- OutputBuffer Methods


                     
         
          

        int result = chunk.getLength();

        if (result <= 0) {
            return 0;
        }

        // Calculate chunk header
        int pos = 7;
        int current = result;
        while (current > 0) {
            int digit = current % 16;
            current = current / 16;
            chunkLength[pos--] = HexUtils.HEX[digit];
        }
        chunkHeader.setBytes(chunkLength, pos + 1, 9 - pos);
        buffer.doWrite(chunkHeader, res);

        buffer.doWrite(chunk, res);

        chunkHeader.setBytes(chunkLength, 8, 2);
        buffer.doWrite(chunkHeader, res);

        return result;

    
public longend()
End the current request. It is acceptable to write extra bytes using buffer.doWrite during the execution of this method.


        // Write end chunk
        buffer.doWrite(END_CHUNK, null);
        
        return 0;

    
public org.apache.tomcat.util.buf.ByteChunkgetEncodingName()
Return the name of the associated encoding; Here, the value is "identity".

        return ENCODING;
    
public voidrecycle()
Make the filter ready to process the next request.

    
public voidsetBuffer(org.apache.coyote.OutputBuffer buffer)
Set the next buffer in the filter pipeline.

        this.buffer = buffer;
    
public voidsetResponse(org.apache.coyote.Response response)
Some filters need additional parameters from the response. All the necessary reading can occur in that method, as this method is called after the response header processing is complete.