|
22 | 22 | import java.io.OutputStream; |
23 | 23 | import java.io.UncheckedIOException; |
24 | 24 |
|
| 25 | +import org.apache.commons.io.UncheckedIO; |
| 26 | + |
25 | 27 | /** |
26 | 28 | * A {@link FilterOutputStream} that throws {@link UncheckedIOException} instead of {@link UncheckedIOException}. |
27 | 29 | * |
@@ -57,63 +59,39 @@ public UncheckedFilterOutputStream(final OutputStream outputStream) { |
57 | 59 | */ |
58 | 60 | @Override |
59 | 61 | public void close() throws UncheckedIOException { |
60 | | - try { |
61 | | - super.close(); |
62 | | - } catch (final IOException e) { |
63 | | - uncheck(e); |
64 | | - } |
| 62 | + UncheckedIO.run(super::close); |
65 | 63 | } |
66 | 64 |
|
67 | 65 | /** |
68 | 66 | * Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}. |
69 | 67 | */ |
70 | 68 | @Override |
71 | 69 | public void flush() throws UncheckedIOException { |
72 | | - try { |
73 | | - super.flush(); |
74 | | - } catch (final IOException e) { |
75 | | - uncheck(e); |
76 | | - } |
77 | | - } |
78 | | - |
79 | | - private void uncheck(final IOException e) { |
80 | | - throw new UncheckedIOException(e); |
| 70 | + UncheckedIO.run(super::flush); |
81 | 71 | } |
82 | 72 |
|
83 | 73 | /** |
84 | 74 | * Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}. |
85 | 75 | */ |
86 | 76 | @Override |
87 | 77 | public void write(final byte[] b) throws UncheckedIOException { |
88 | | - try { |
89 | | - super.write(b); |
90 | | - } catch (final IOException e) { |
91 | | - uncheck(e); |
92 | | - } |
| 78 | + UncheckedIO.accept(super::write, b); |
93 | 79 | } |
94 | 80 |
|
95 | 81 | /** |
96 | 82 | * Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}. |
97 | 83 | */ |
98 | 84 | @Override |
99 | 85 | public void write(final byte[] b, final int off, final int len) throws UncheckedIOException { |
100 | | - try { |
101 | | - super.write(b, off, len); |
102 | | - } catch (final IOException e) { |
103 | | - uncheck(e); |
104 | | - } |
| 86 | + UncheckedIO.accept(super::write, b, off, len); |
105 | 87 | } |
106 | 88 |
|
107 | 89 | /** |
108 | 90 | * Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}. |
109 | 91 | */ |
110 | 92 | @Override |
111 | 93 | public void write(final int b) throws UncheckedIOException { |
112 | | - try { |
113 | | - super.write(b); |
114 | | - } catch (final IOException e) { |
115 | | - uncheck(e); |
116 | | - } |
| 94 | + UncheckedIO.accept(super::write, b); |
117 | 95 | } |
118 | 96 |
|
119 | 97 | } |
0 commit comments