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
23 import javax.servlet.ServletOutputStream;
24 import javax.servlet.WriteListener;
25
26
27
28
29
30 class SwitchableOutputStream extends ServletOutputStream
31 {
32
33 ServletOutputStream _delegate = null;
34 ResponseSwitch _responseSwitch = null;
35
36 public SwitchableOutputStream(ServletOutputStream delegate, ResponseSwitch responseSwitch)
37 {
38 _delegate = delegate;
39 _responseSwitch = responseSwitch;
40 }
41
42 @Override
43 public void close() throws IOException
44 {
45 if (_responseSwitch.isEnabled())
46 {
47 _delegate.close();
48 }
49 }
50
51 @Override
52 public void flush() throws IOException
53 {
54 if (_responseSwitch.isEnabled())
55 {
56 _delegate.flush();
57 }
58 }
59
60 @Override
61 public void write(byte[] b, int off, int len) throws IOException
62 {
63 if (_responseSwitch.isEnabled())
64 {
65 _delegate.write(b, off, len);
66 }
67 }
68
69 @Override
70 public void write(byte[] b) throws IOException
71 {
72 if (_responseSwitch.isEnabled())
73 {
74 _delegate.write(b);
75 }
76 }
77
78 @Override
79 public void write(int b) throws IOException
80 {
81 if (_responseSwitch.isEnabled())
82 {
83 _delegate.write(b);
84 }
85 }
86
87 @Override
88 public boolean isReady()
89 {
90 if (_responseSwitch.isEnabled())
91 {
92 return _delegate.isReady();
93 }
94
95 return true;
96 }
97
98 @Override
99 public void setWriteListener(WriteListener wl)
100 {
101 if (_responseSwitch.isEnabled())
102 {
103 _delegate.setWriteListener(wl);
104 }
105 }
106
107 }