1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.io.test;
18
19 import static org.junit.jupiter.api.Assertions.fail;
20
21 import java.io.IOException;
22 import java.io.OutputStream;
23
24 import org.apache.commons.io.output.ProxyOutputStream;
25
26
27
28
29 public class ThrowOnFlushAndCloseOutputStream extends ProxyOutputStream {
30
31 private boolean throwOnFlush;
32 private boolean throwOnClose;
33
34
35
36
37
38
39 public ThrowOnFlushAndCloseOutputStream(final OutputStream proxy, final boolean throwOnFlush,
40 final boolean throwOnClose) {
41 super(proxy);
42 this.throwOnFlush = throwOnFlush;
43 this.throwOnClose = throwOnClose;
44 }
45
46
47 @Override
48 public void close() throws IOException {
49 if (throwOnClose) {
50 fail(getClass().getSimpleName() + ".close() called.");
51 }
52 super.close();
53 }
54
55
56 @Override
57 public void flush() throws IOException {
58 if (throwOnFlush) {
59 fail(getClass().getSimpleName() + ".flush() called.");
60 }
61 super.flush();
62 }
63
64 public void off() {
65 throwOnFlush = false;
66 throwOnClose = false;
67 }
68
69 }