Skip to content

Commit c382f5d

Browse files
committed
Resue org.apache.commons.io.input.ClosedInputStream.CLOSED_INPUT_STREAM.
1 parent e997b9c commit c382f5d

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public AutoCloseInputStream(final InputStream in) {
6262
@Override
6363
public void close() throws IOException {
6464
in.close();
65-
in = new ClosedInputStream();
65+
in = ClosedInputStream.CLOSED_INPUT_STREAM;
6666
}
6767

6868
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ protected <T extends InputStream> InputStream toInputStream(
307307
final InputStreamConstructor<T> isConstructor) {
308308
int remaining = count;
309309
if (remaining == 0) {
310-
return new ClosedInputStream();
310+
return ClosedInputStream.CLOSED_INPUT_STREAM;
311311
}
312312
final List<T> list = new ArrayList<>(buffers.size());
313313
for (final byte[] buf : buffers) {

src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class TaggedInputStreamTest {
3636

3737
@Test
3838
public void testEmptyStream() throws IOException {
39-
final InputStream stream = new TaggedInputStream(new ClosedInputStream());
39+
final InputStream stream = new TaggedInputStream(ClosedInputStream.CLOSED_INPUT_STREAM);
4040
assertEquals(0, stream.available());
4141
assertEquals(-1, stream.read());
4242
assertEquals(-1, stream.read(new byte[1]));
@@ -111,8 +111,7 @@ public void testBrokenStream() {
111111
@Test
112112
public void testOtherException() throws Exception {
113113
final IOException exception = new IOException("test exception");
114-
final InputStream closed = new ClosedInputStream();
115-
final TaggedInputStream stream = new TaggedInputStream(closed);
114+
final TaggedInputStream stream = new TaggedInputStream(ClosedInputStream.CLOSED_INPUT_STREAM);
116115

117116
assertFalse(stream.isCauseOf(exception));
118117
assertFalse(stream.isCauseOf(

0 commit comments

Comments
 (0)