FileDocCategorySizeDatePackage
IdentityOutputFilter.javaAPI DocGlassfish v2 API6027Fri May 04 22:32:42 BST 2007org.apache.coyote.http11.filters

IdentityOutputFilter

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

Fields Summary
protected static final String
ENCODING_NAME
protected static final org.apache.tomcat.util.buf.ByteChunk
ENCODING
protected long
contentLength
Content length.
protected long
remaining
Remaining bytes.
protected org.apache.coyote.OutputBuffer
buffer
Next buffer in the pipeline.
Constructors Summary
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


        int result = -1;

        if (contentLength >= 0) {
            if (remaining > 0) {
                result = chunk.getLength();
                if (result > remaining) {
                    // The chunk is longer than the number of bytes remaining
                    // in the body; changing the chunk length to the number
                    // of bytes remaining
                    chunk.setBytes(chunk.getBytes(), chunk.getStart(), 
                                   (int) remaining);
                    result = (int) remaining;
                    remaining = 0;
                } else {
                    remaining = remaining - result;
                }
                buffer.doWrite(chunk, res);
            } else {
                // No more bytes left to be written : return -1 and clear the 
                // buffer
                chunk.recycle();
                result = -1;
            }
        } else {
            // If no content length was set, just write the bytes
            buffer.doWrite(chunk, res);
            result = chunk.getLength();
        }

        return result;

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


        if (remaining > 0)
            return remaining;
        return 0;

    
public longgetContentLength()
Get content length.



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


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

        return ENCODING;
    
public longgetRemaining()
Get remaining bytes.

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

        contentLength = -1;
        remaining = 0;
    
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.

        contentLength = response.getContentLength();
        remaining = contentLength;