Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SwitchableOutputStream |
|
| 1.8333333333333333;1.833 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.apache.myfaces.shared.view; | |
20 | ||
21 | import java.io.IOException; | |
22 | import java.io.OutputStream; | |
23 | ||
24 | import javax.servlet.ServletOutputStream; | |
25 | ||
26 | /** | |
27 | * Delegates the standard OutputStream-methods (close, flush, write) | |
28 | * to the given ServletOutputStream, if the ResponseSwitch is enabled | |
29 | */ | |
30 | class SwitchableOutputStream extends ServletOutputStream | |
31 | { | |
32 | ||
33 | 0 | OutputStream _delegate = null; |
34 | 0 | ResponseSwitch _responseSwitch = null; |
35 | ||
36 | public SwitchableOutputStream(ServletOutputStream delegate, ResponseSwitch responseSwitch) | |
37 | 0 | { |
38 | 0 | _delegate = delegate; |
39 | 0 | _responseSwitch = responseSwitch; |
40 | 0 | } |
41 | ||
42 | @Override | |
43 | public void close() throws IOException | |
44 | { | |
45 | 0 | if (_responseSwitch.isEnabled()) |
46 | { | |
47 | 0 | _delegate.close(); |
48 | } | |
49 | 0 | } |
50 | ||
51 | @Override | |
52 | public void flush() throws IOException | |
53 | { | |
54 | 0 | if (_responseSwitch.isEnabled()) |
55 | { | |
56 | 0 | _delegate.flush(); |
57 | } | |
58 | 0 | } |
59 | ||
60 | @Override | |
61 | public void write(byte[] b, int off, int len) throws IOException | |
62 | { | |
63 | 0 | if (_responseSwitch.isEnabled()) |
64 | { | |
65 | 0 | _delegate.write(b, off, len); |
66 | } | |
67 | 0 | } |
68 | ||
69 | @Override | |
70 | public void write(byte[] b) throws IOException | |
71 | { | |
72 | 0 | if (_responseSwitch.isEnabled()) |
73 | { | |
74 | 0 | _delegate.write(b); |
75 | } | |
76 | 0 | } |
77 | ||
78 | @Override | |
79 | public void write(int b) throws IOException | |
80 | { | |
81 | 0 | if (_responseSwitch.isEnabled()) |
82 | { | |
83 | 0 | _delegate.write(b); |
84 | } | |
85 | 0 | } |
86 | ||
87 | } |