1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.javadpkg.io.impl;
20
21 import java.io.IOException;
22 import java.io.OutputStream;
23
24 import net.sourceforge.javadpkg.io.CloseHandler;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class UncloseableOutputStream extends OutputStream {
40
41
42
43 private OutputStream out;
44
45 private CloseHandler closeHandler;
46
47
48
49
50
51
52
53
54
55
56
57
58 public UncloseableOutputStream(OutputStream out) {
59 super();
60
61 if (out == null)
62 throw new IllegalArgumentException("Argument out is null.");
63
64 this.out = out;
65 this.closeHandler = null;
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 public UncloseableOutputStream(OutputStream out, CloseHandler closeHandler) {
82 super();
83
84 if (out == null)
85 throw new IllegalArgumentException("Argument out is null.");
86 if (closeHandler == null)
87 throw new IllegalArgumentException("Argument closeHandler is null.");
88
89 this.out = out;
90 this.closeHandler = closeHandler;
91 }
92
93
94 @Override
95 public void write(int b) throws IOException {
96 this.out.write(b);
97 }
98
99
100 @Override
101 public void write(byte[] b) throws IOException {
102 this.out.write(b);
103 }
104
105
106 @Override
107 public void write(byte[] b, int off, int len) throws IOException {
108 this.out.write(b, off, len);
109 }
110
111
112 @Override
113 public void flush() throws IOException {
114 this.out.flush();
115 }
116
117
118 @Override
119 public void close() throws IOException {
120 this.out.flush();
121 if (this.closeHandler != null)
122 this.closeHandler.closed();
123 }
124
125
126 }