Skip to content

Commit b5fecb3

Browse files
author
Gary Gregory
committed
Reuse our own code
1 parent 0cdb6b3 commit b5fecb3

1 file changed

Lines changed: 7 additions & 29 deletions

File tree

src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.io.OutputStream;
2323
import java.io.UncheckedIOException;
2424

25+
import org.apache.commons.io.UncheckedIO;
26+
2527
/**
2628
* A {@link FilterOutputStream} that throws {@link UncheckedIOException} instead of {@link UncheckedIOException}.
2729
*
@@ -57,63 +59,39 @@ public UncheckedFilterOutputStream(final OutputStream outputStream) {
5759
*/
5860
@Override
5961
public void close() throws UncheckedIOException {
60-
try {
61-
super.close();
62-
} catch (final IOException e) {
63-
uncheck(e);
64-
}
62+
UncheckedIO.run(super::close);
6563
}
6664

6765
/**
6866
* Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}.
6967
*/
7068
@Override
7169
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);
8171
}
8272

8373
/**
8474
* Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}.
8575
*/
8676
@Override
8777
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);
9379
}
9480

9581
/**
9682
* Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}.
9783
*/
9884
@Override
9985
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);
10587
}
10688

10789
/**
10890
* Calls this method's super and rethrow {@link IOException} as {@link UncheckedIOException}.
10991
*/
11092
@Override
11193
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);
11795
}
11896

11997
}

0 commit comments

Comments
 (0)