FileDocCategorySizeDatePackage
ChunkedOutputFilter.javaAPI DocGlassfish v2 API5800Fri May 04 22:32:42 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());
        String endChunkValue = "0\r\n\r\n";
        END_CHUNK.setBytes(endChunkValue.getBytes(), 
                           0, endChunkValue.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.