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 package org.apache.coyote.http11.filters;
18
19 import java.io.IOException;
20 import java.nio.ByteBuffer;
21
22 import org.apache.coyote.Response;
23 import org.apache.coyote.http11.HttpOutputBuffer;
24 import org.apache.coyote.http11.OutputFilter;
25
26 /**
27 * Void output filter, which silently swallows bytes written. Used with a 204
28 * status (no content) or a HEAD request.
29 *
30 * @author Remy Maucherat
31 */
32 public class VoidOutputFilter implements OutputFilter {
33
34 private HttpOutputBuffer buffer = null;
35
36
37 // --------------------------------------------------- OutputBuffer Methods
38
39 @Override
40 public int doWrite(ByteBuffer chunk) throws IOException {
41 return chunk.remaining();
42 }
43
44
45 @Override
46 public long getBytesWritten() {
47 return 0;
48 }
49
50
51 // --------------------------------------------------- OutputFilter Methods
52
53 @Override
54 public void setResponse(Response response) {
55 // NOOP: No need for parameters from response in this filter
56 }
57
58
59 @Override
60 public void setBuffer(HttpOutputBuffer buffer) {
61 this.buffer = buffer;
62 }
63
64
65 @Override
66 public void flush() throws IOException {
67 this.buffer.flush();
68 }
69
70
71 @Override
72 public void recycle() {
73 buffer = null;
74 }
75
76
77 @Override
78 public void end() throws IOException {
79 buffer.end();
80 }
81 }
82