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.OutputBuffer;
025: import org.apache.coyote.Response;
026: import org.apache.coyote.http11.OutputFilter;
027:
028: /**
029: * Void output filter, which silently swallows bytes written. Used with a 204
030: * status (no content) or a HEAD request.
031: *
032: * @author Remy Maucherat
033: */
034: public class VoidOutputFilter implements OutputFilter {
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: /**
051: * Next buffer in the pipeline.
052: */
053: protected OutputBuffer buffer;
054:
055: // --------------------------------------------------- OutputBuffer Methods
056:
057: /**
058: * Write some bytes.
059: *
060: * @return number of bytes written by the filter
061: */
062: public int doWrite(ByteChunk chunk, Response res)
063: throws IOException {
064:
065: return chunk.getLength();
066:
067: }
068:
069: // --------------------------------------------------- OutputFilter Methods
070:
071: /**
072: * Some filters need additional parameters from the response. All the
073: * necessary reading can occur in that method, as this method is called
074: * after the response header processing is complete.
075: */
076: public void setResponse(Response response) {
077: }
078:
079: /**
080: * Set the next buffer in the filter pipeline.
081: */
082: public void setBuffer(OutputBuffer buffer) {
083: this .buffer = buffer;
084: }
085:
086: /**
087: * Make the filter ready to process the next request.
088: */
089: public void recycle() {
090: }
091:
092: /**
093: * Return the name of the associated encoding; Here, the value is
094: * "identity".
095: */
096: public ByteChunk getEncodingName() {
097: return ENCODING;
098: }
099:
100: /**
101: * End the current request. It is acceptable to write extra bytes using
102: * buffer.doWrite during the execution of this method.
103: *
104: * @return Should return 0 unless the filter does some content length
105: * delimitation, in which case the number is the amount of extra bytes or
106: * missing bytes, which would indicate an error.
107: * Note: It is recommended that extra bytes be swallowed by the filter.
108: */
109: public long end() throws IOException {
110: return 0;
111: }
112:
113: }
|