001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.coyote.http11.filters;
019:
020: import java.io.IOException;
021:
022: import org.apache.tomcat.util.buf.ByteChunk;
023:
024: import org.apache.coyote.InputBuffer;
025: import org.apache.coyote.Request;
026: import org.apache.coyote.http11.InputFilter;
027:
028: /**
029: * Void input filter, which returns -1 when attempting a read. Used with a GET,
030: * HEAD, or a similar request.
031: *
032: * @author Remy Maucherat
033: */
034: public class VoidInputFilter implements InputFilter {
035:
036: // -------------------------------------------------------------- Constants
037:
038: protected static final String ENCODING_NAME = "void";
039: protected static final ByteChunk ENCODING = new ByteChunk();
040:
041: // ----------------------------------------------------- Static Initializer
042:
043: static {
044: ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME
045: .length());
046: }
047:
048: // ----------------------------------------------------- Instance Variables
049:
050: // --------------------------------------------------- OutputBuffer Methods
051:
052: /**
053: * Write some bytes.
054: *
055: * @return number of bytes written by the filter
056: */
057: public int doRead(ByteChunk chunk, Request req) throws IOException {
058:
059: return -1;
060:
061: }
062:
063: // --------------------------------------------------- OutputFilter Methods
064:
065: /**
066: * Set the associated reauest.
067: */
068: public void setRequest(Request request) {
069: }
070:
071: /**
072: * Set the next buffer in the filter pipeline.
073: */
074: public void setBuffer(InputBuffer buffer) {
075: }
076:
077: /**
078: * Make the filter ready to process the next request.
079: */
080: public void recycle() {
081: }
082:
083: /**
084: * Return the name of the associated encoding; Here, the value is
085: * "void".
086: */
087: public ByteChunk getEncodingName() {
088: return ENCODING;
089: }
090:
091: /**
092: * End the current request. It is acceptable to write extra bytes using
093: * buffer.doWrite during the execution of this method.
094: *
095: * @return Should return 0 unless the filter does some content length
096: * delimitation, in which case the number is the amount of extra bytes or
097: * missing bytes, which would indicate an error.
098: * Note: It is recommended that extra bytes be swallowed by the filter.
099: */
100: public long end() throws IOException {
101: return 0;
102: }
103:
104: /**
105: * Amount of bytes still available in a buffer.
106: */
107: public int available() {
108: return 0;
109: }
110:
111: }
|