KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > coyote > http11 > filters > VoidOutputFilter


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.coyote.http11.filters;
19
20 import java.io.IOException JavaDoc;
21
22 import org.apache.tomcat.util.buf.ByteChunk;
23
24 import org.apache.coyote.OutputBuffer;
25 import org.apache.coyote.Response;
26 import org.apache.coyote.http11.OutputFilter;
27
28 /**
29  * Void output filter, which silently swallows bytes written. Used with a 204
30  * status (no content) or a HEAD request.
31  *
32  * @author Remy Maucherat
33  */

34 public class VoidOutputFilter implements OutputFilter {
35
36
37     // -------------------------------------------------------------- Constants
38

39
40     protected static final String JavaDoc ENCODING_NAME = "void";
41     protected static final ByteChunk ENCODING = new ByteChunk();
42
43
44     // ----------------------------------------------------- Static Initializer
45

46
47     static {
48         ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length());
49     }
50
51
52     // ----------------------------------------------------- Instance Variables
53

54
55     /**
56      * Next buffer in the pipeline.
57      */

58     protected OutputBuffer buffer;
59
60
61     // --------------------------------------------------- OutputBuffer Methods
62

63
64     /**
65      * Write some bytes.
66      *
67      * @return number of bytes written by the filter
68      */

69     public int doWrite(ByteChunk chunk, Response res)
70         throws IOException JavaDoc {
71
72         return chunk.getLength();
73
74     }
75
76
77     // --------------------------------------------------- OutputFilter Methods
78

79
80     /**
81      * Some filters need additional parameters from the response. All the
82      * necessary reading can occur in that method, as this method is called
83      * after the response header processing is complete.
84      */

85     public void setResponse(Response response) {
86     }
87
88
89     /**
90      * Set the next buffer in the filter pipeline.
91      */

92     public void setBuffer(OutputBuffer buffer) {
93         this.buffer = buffer;
94     }
95
96
97     /**
98      * Make the filter ready to process the next request.
99      */

100     public void recycle() {
101     }
102
103
104     /**
105      * Return the name of the associated encoding; Here, the value is
106      * "identity".
107      */

108     public ByteChunk getEncodingName() {
109         return ENCODING;
110     }
111
112
113     /**
114      * End the current request. It is acceptable to write extra bytes using
115      * buffer.doWrite during the execution of this method.
116      *
117      * @return Should return 0 unless the filter does some content length
118      * delimitation, in which case the number is the amount of extra bytes or
119      * missing bytes, which would indicate an error.
120      * Note: It is recommended that extra bytes be swallowed by the filter.
121      */

122     public long end()
123         throws IOException JavaDoc {
124         return 0;
125     }
126
127
128 }
129
Popular Tags