1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
28
29
30
31
32
33
34 class SwitchableOutputStream extends ServletOutputStream
35 {
36
37 OutputStream _delegate = null;
38 ResponseSwitch _responseSwitch = null;
39
40 public SwitchableOutputStream(ServletOutputStream delegate, ResponseSwitch responseSwitch)
41 {
42 _delegate = delegate;
43 _responseSwitch = responseSwitch;
44 }
45
46 @Override
47 public void close() throws IOException
48 {
49 if (_responseSwitch.isEnabled())
50 {
51 _delegate.close();
52 }
53 }
54
55 @Override
56 public void flush() throws IOException
57 {
58 if (_responseSwitch.isEnabled())
59 {
60 _delegate.flush();
61 }
62 }
63
64 @Override
65 public void write(byte[] b, int off, int len) throws IOException
66 {
67 if (_responseSwitch.isEnabled())
68 {
69 _delegate.write(b, off, len);
70 }
71 }
72
73 @Override
74 public void write(byte[] b) throws IOException
75 {
76 if (_responseSwitch.isEnabled())
77 {
78 _delegate.write(b);
79 }
80 }
81
82 @Override
83 public void write(int b) throws IOException
84 {
85 if (_responseSwitch.isEnabled())
86 {
87 _delegate.write(b);
88 }
89 }
90
91 }