Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Licensed to the Apache Software Foundation (ASF) under one or more
   *  contributor license agreements.  See the NOTICE file distributed with
   *  this work for additional information regarding copyright ownership.
   *  The ASF licenses this file to You under the Apache License, Version 2.0
   *  (the "License"); you may not use this file except in compliance with
   *  the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 
 package org.apache.coyote.http11.filters;
 
Input filter responsible for reading and buffering the request body, so that it does not interfere with client SSL handshake messages.
 
 public class BufferedInputFilter implements InputFilter {
 
     // -------------------------------------------------------------- Constants
 
     private static final String ENCODING_NAME = "buffered";
     private static final ByteChunk ENCODING = new ByteChunk();
 
 
     // ----------------------------------------------------- Instance Variables
 
     private ByteChunk buffered = null;
     private ByteChunk tempRead = new ByteChunk(1024);
     private InputBuffer buffer;
     private boolean hasRead = false;
 
 
     // ----------------------------------------------------- Static Initializer
 
     static {
     }
 
 
     // --------------------------------------------------------- Public Methods
 

    
Set the buffering limit. This should be reset every time the buffer is used.
 
     public void setLimit(int limit) {
         if ( == null) {
              = new ByteChunk(4048);
             .setLimit(limit);
         }
     }
 
 
     // ---------------------------------------------------- InputBuffer Methods
 

    
Reads the request body and buffers it.
 
     public void setRequest(Request request) {
         // save off the Request body
         try {
             while (.doRead(request) >= 0) {
                 .append();
                 .recycle();
             }
         } catch(IOException iex) {
             // Ignore
         }
     }

    
Fills the given ByteChunk with the buffered request body.
 
     public int doRead(ByteChunk chunkRequest requestthrows IOException {
         if ( || .getLength() <= 0) {
             return -1;
         } else {
             chunk.setBytes(.getBytes(), .getStart(),
                            .getLength());
              = true;
         }
         return chunk.getLength();
     }
 
    public void setBuffer(InputBuffer buffer) {
        this. = buffer;
    }
    public void recycle() {
        if ( != null) {
            if (.getBuffer() != null 
                    && .getBuffer().length > 65536) {
                 = null;
            } else {
                .recycle();
            }
        }
        .recycle();
         = false;
         = null;
    }
    public ByteChunk getEncodingName() {
        return ;
    }
    public long end() throws IOException {
        return 0;
    }
    public int available() {
        return .getLength();
    }
    
New to GrepCode? Check out our FAQ X