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

IdentityInputFilter

public class IdentityInputFilter extends Object implements org.apache.coyote.http11.InputFilter
Identity input 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.InputBuffer
buffer
Next buffer in the pipeline.
protected org.apache.tomcat.util.buf.ByteChunk
endChunk
Chunk used to read leftover bytes.
Constructors Summary
Methods Summary
public intavailable()
Amount of bytes still available in a buffer.

        return 0;
    
public intdoRead(org.apache.tomcat.util.buf.ByteChunk chunk, org.apache.coyote.Request req)
Read bytes.

return
If the filter does request length control, this value is significant; it should be the number of bytes consumed from the buffer, up until the end of the current request body, or the buffer length, whichever is greater. If the filter does not do request body length control, the returned value should be -1.


        int result = -1;

        if (contentLength >= 0) {
            if (remaining > 0) {
                int nRead = buffer.doRead(chunk, req);
                if (nRead > 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;
                } else {
                    result = nRead;
                }
                remaining = remaining - nRead;
            } else {
                // No more bytes left to be read : return -1 and clear the 
                // buffer
                chunk.recycle();
                result = -1;
            }
        }

        return result;

    
public longend()
End the current request.


        // Consume extra bytes.
        while (remaining > 0) {
            int nread = buffer.doRead(endChunk, null);
            if (nread > 0 ) {
                remaining = remaining - nread;
            } else { // errors are handled higher up.
                remaining = 0;
            }
        }

        // If too many bytes were read, return the amount.
        return -remaining;

    
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;
        endChunk.recycle();
    
public voidsetBuffer(org.apache.coyote.InputBuffer buffer)
Set the next buffer in the filter pipeline.

        this.buffer = buffer;
    
public voidsetRequest(org.apache.coyote.Request request)
Read the content length from the request.

        contentLength = request.getContentLengthLong();
        remaining = contentLength;