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