Add NullInputStream.INSTANCE.
Add
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -96,6 +96,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add NullWriter.INSTANCE and deprecate NULL_WRITER.
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add NullInputStream.INSTANCE.
+ </action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

MODIFY
src/main/java/org/apache/commons/io/input/NullInputStream.java
src/main/java/org/apache/commons/io/input/NullInputStream.java
*/
public class NullInputStream extends InputStream {
+ /**
+ * The singleton instance.
+ *
+ * @since 2.12.0
+ */
+ public static final NullInputStream INSTANCE = new NullInputStream();
+
private final long size;
private long position;
private long mark = -1;

MODIFY
src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
@@ -253,7 +253,7 @@ public void testDataBytesCalled() throws Exception {
@Test
public void testGetObservers0() throws IOException {
- try (final ObservableInputStream ois = new ObservableInputStream(new NullInputStream())) {
+ try (final ObservableInputStream ois = new ObservableInputStream(NullInputStream.INSTANCE)) {
assertTrue(ois.getObservers().isEmpty());
}
}
@@ -261,7 +261,7 @@ public void testGetObservers0() throws IOException {
@Test
public void testGetObservers1() throws IOException {
final DataViewObserver observer0 = new DataViewObserver();
- try (final ObservableInputStream ois = new ObservableInputStream(new NullInputStream(), observer0)) {
+ try (final ObservableInputStream ois = new ObservableInputStream(NullInputStream.INSTANCE, observer0)) {
assertEquals(observer0, ois.getObservers().get(0));
}
}
@@ -270,7 +270,7 @@ public void testGetObservers1() throws IOException {
public void testGetObserversOrder() throws IOException {
final DataViewObserver observer0 = new DataViewObserver();
final DataViewObserver observer1 = new DataViewObserver();
- try (final ObservableInputStream ois = new ObservableInputStream(new NullInputStream(), observer0, observer1)) {
+ try (final ObservableInputStream ois = new ObservableInputStream(NullInputStream.INSTANCE, observer0, observer1)) {
assertEquals(observer0, ois.getObservers().get(0));
assertEquals(observer1, ois.getObservers().get(1));
}

MODIFY
src/test/java/org/apache/commons/io/output/CloseShieldWriterTest.java
src/test/java/org/apache/commons/io/output/CloseShieldWriterTest.java
private Writer shielded;
+ @SuppressWarnings("resource")
@BeforeEach
public void setUp() {
original = spy(new StringBuilderWriter());

MODIFY
src/test/java/org/apache/commons/io/test/ThrowOnCloseInputStream.java
src/test/java/org/apache/commons/io/test/ThrowOnCloseInputStream.java
/**
* Default ctor.
*/
- @SuppressWarnings("resource")
public ThrowOnCloseInputStream() {
- super(new NullInputStream());
+ super(NullInputStream.INSTANCE);
}
/**

Add NullInputStream.INSTANCE.

Add @SuppressWarnings("resource").