You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/01/02 13:36:59 UTC
(commons-io) branch master updated (2077753f0 -> 07ad1b3cb)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
from 2077753f0 Fix release description
new f78f7a256 Add ProxyInputStream.setReference(InputStream), was package-private setIn(InputStream)
new 07ad1b3cb Add ProxyOutputStream.setReference(OutputStream)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 2 ++
.../apache/commons/io/input/ProxyInputStream.java | 7 +++++--
.../apache/commons/io/output/ProxyOutputStream.java | 12 ++++++++++++
.../commons/io/input/ProxyInputStreamTest.java | 10 +++++-----
.../commons/io/output/ProxyOutputStreamTest.java | 20 ++++++++++++++++----
5 files changed, 40 insertions(+), 11 deletions(-)
(commons-io) 01/02: Add ProxyInputStream.setReference(InputStream), was package-private setIn(InputStream)
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit f78f7a2565a7cd454196719eb11e02a09401e0b3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jan 2 08:30:23 2025 -0500
Add ProxyInputStream.setReference(InputStream), was package-private
setIn(InputStream)
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/io/input/ProxyInputStream.java | 7 +++++--
.../java/org/apache/commons/io/input/ProxyInputStreamTest.java | 10 +++++-----
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f4de083fe..a5f4ae83f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -58,6 +58,7 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">Add AbstractByteArrayOutputStream.write(CharSequence, Charset).</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add AbstractByteArrayOutputStream.write(byte[]).</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add RandomAccessFileOutputStream.getRandomAccessFile().</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">Add ProxyInputStream.setReference(InputStream), was package-private setIn(InputStream).</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">Bump commons.bytebuddy.version from 1.15.10 to 1.15.11 #710.</action>
</release>
diff --git a/src/main/java/org/apache/commons/io/input/ProxyInputStream.java b/src/main/java/org/apache/commons/io/input/ProxyInputStream.java
index 8dfa2391d..eecee50a5 100644
--- a/src/main/java/org/apache/commons/io/input/ProxyInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/ProxyInputStream.java
@@ -367,12 +367,15 @@ public abstract class ProxyInputStream extends FilterInputStream {
}
/**
- * Package-private for testing.
+ * Sets the underlying input stream.
*
* @param in The input stream to set in {@link java.io.FilterInputStream#in}.
+ * @return this instance.
+ * @since 2.19.0
*/
- void setIn(final InputStream in) {
+ public ProxyInputStream setReference(final InputStream in) {
this.in = in;
+ return this;
}
/**
diff --git a/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java b/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
index 2b5ba176f..04ab4ffc7 100644
--- a/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
@@ -145,11 +145,11 @@ public class ProxyInputStreamTest<T extends ProxyInputStream> {
public void testAvailableNull() throws IOException {
try (T inputStream = createFixture(null)) {
assertEquals(0, inputStream.available());
- inputStream.setIn(createFixture());
+ inputStream.setReference(createFixture());
assertEquals(3, inputStream.available());
IOUtils.toByteArray(inputStream);
assertEquals(0, inputStream.available());
- inputStream.setIn(null);
+ inputStream.setReference(null);
assertEquals(0, inputStream.available());
}
}
@@ -162,11 +162,11 @@ public class ProxyInputStreamTest<T extends ProxyInputStream> {
public void testMarkOnNull() throws IOException {
try (T inputStream = createFixture(null)) {
inputStream.mark(1);
- inputStream.setIn(createFixture());
+ inputStream.setReference(createFixture());
inputStream.mark(1);
IOUtils.toByteArray(inputStream);
inputStream.mark(1);
- inputStream.setIn(null);
+ inputStream.setReference(null);
inputStream.mark(1);
}
}
@@ -192,7 +192,7 @@ public class ProxyInputStreamTest<T extends ProxyInputStream> {
public void testMarkSupportedOnNull() throws IOException {
try (ProxyInputStream fixture = createFixture()) {
assertMarkSupportedEquals(fixture);
- fixture.setIn(null);
+ fixture.setReference(null);
assertFalse(fixture.markSupported());
}
}
(commons-io) 02/02: Add ProxyOutputStream.setReference(OutputStream)
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 07ad1b3cb5d16fbc49e4d46927c93b102f71815c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jan 2 08:36:51 2025 -0500
Add ProxyOutputStream.setReference(OutputStream)
---
src/changes/changes.xml | 1 +
.../apache/commons/io/output/ProxyOutputStream.java | 12 ++++++++++++
.../commons/io/output/ProxyOutputStreamTest.java | 20 ++++++++++++++++----
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a5f4ae83f..c3b2a3027 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -59,6 +59,7 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">Add AbstractByteArrayOutputStream.write(byte[]).</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add RandomAccessFileOutputStream.getRandomAccessFile().</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add ProxyInputStream.setReference(InputStream), was package-private setIn(InputStream).</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">Add ProxyOutputStream.setReference(OutputStream).</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot, Gary Gregory">Bump commons.bytebuddy.version from 1.15.10 to 1.15.11 #710.</action>
</release>
diff --git a/src/main/java/org/apache/commons/io/output/ProxyOutputStream.java b/src/main/java/org/apache/commons/io/output/ProxyOutputStream.java
index 303d02943..766f5f83a 100644
--- a/src/main/java/org/apache/commons/io/output/ProxyOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/ProxyOutputStream.java
@@ -116,6 +116,18 @@ public class ProxyOutputStream extends FilterOutputStream {
throw e;
}
+ /**
+ * Sets the underlying output stream.
+ *
+ * @param out the underlying output stream.
+ * @return this instance.
+ * @since 2.19.0
+ */
+ public ProxyOutputStream setReference(final OutputStream out) {
+ this.out = out;
+ return this;
+ }
+
/**
* Invokes the delegate's {@code write(byte[])} method.
* @param bts the bytes to write
diff --git a/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
index 5f46a98a8..7420b41d5 100644
--- a/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
@@ -16,14 +16,15 @@
*/
package org.apache.commons.io.output;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -34,7 +35,7 @@ public class ProxyOutputStreamTest {
private ByteArrayOutputStream original;
- private OutputStream proxied;
+ private ProxyOutputStream proxied;
private final AtomicBoolean hit = new AtomicBoolean();
@@ -43,13 +44,13 @@ public class ProxyOutputStreamTest {
original = new ByteArrayOutputStream() {
@Override
- public synchronized void write(final int ba) {
+ public void write(final byte[] ba) {
hit.set(true);
super.write(ba);
}
@Override
- public void write(final byte[] ba) {
+ public synchronized void write(final int ba) {
hit.set(true);
super.write(ba);
}
@@ -57,6 +58,17 @@ public class ProxyOutputStreamTest {
proxied = new ProxyOutputStream(original);
}
+ @SuppressWarnings("resource")
+ @Test
+ public void testSetReference() throws Exception {
+ assertFalse(hit.get());
+ proxied.setReference(new ByteArrayOutputStream());
+ proxied.write('y');
+ assertFalse(hit.get());
+ assertEquals(0, original.size());
+ assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, original.toByteArray());
+ }
+
@Test
public void testWrite() throws Exception {
assertFalse(hit.get());