Skip to content

Commit b8b0766

Browse files
author
Gary Gregory
committed
Add BrokenInputStream.INSTANCE.
1 parent 93228b3 commit b8b0766

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ The <action> type attribute can be add,update,fix,remove.
6969
<action dev="ggregory" type="add" due-to="Gary Gregory">
7070
Add UncheckedFilterInputStream.
7171
</action>
72+
<action dev="ggregory" type="add" due-to="Gary Gregory">
73+
Add BrokenInputStream.INSTANCE.
74+
</action>
7275
<!-- UPDATE -->
7376
<action dev="ggregory" type="update" due-to="Dependabot">
7477
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
*/
3232
public class BrokenInputStream extends InputStream {
3333

34+
/**
35+
* The singleton instance.
36+
*
37+
* @since 2.12.0
38+
*/
39+
public static final BrokenInputStream INSTANCE = new BrokenInputStream();
40+
3441
/**
3542
* The exception that is thrown by all methods of this class.
3643
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,21 @@ public long getFinishedCount() {
129129

130130
@Test
131131
public void testBrokenInputStreamRead() throws IOException {
132-
try (final ObservableInputStream ois = new ObservableInputStream(new BrokenInputStream())) {
132+
try (final ObservableInputStream ois = new ObservableInputStream(BrokenInputStream.INSTANCE)) {
133133
assertThrows(IOException.class, () -> ois.read());
134134
}
135135
}
136136

137137
@Test
138138
public void testBrokenInputStreamReadBuffer() throws IOException {
139-
try (final ObservableInputStream ois = new ObservableInputStream(new BrokenInputStream())) {
139+
try (final ObservableInputStream ois = new ObservableInputStream(BrokenInputStream.INSTANCE)) {
140140
assertThrows(IOException.class, () -> ois.read(new byte[1]));
141141
}
142142
}
143143

144144
@Test
145145
public void testBrokenInputStreamReadSubBuffer() throws IOException {
146-
try (final ObservableInputStream ois = new ObservableInputStream(new BrokenInputStream())) {
146+
try (final ObservableInputStream ois = new ObservableInputStream(BrokenInputStream.INSTANCE)) {
147147
assertThrows(IOException.class, () -> ois.read(new byte[2], 0, 1));
148148
}
149149
}

0 commit comments

Comments
 (0)