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 2022/02/13 22:14:50 UTC
[commons-compress] 02/05: In most IOUtil methods, the target may be null to simulate output to dev/null on Linux and NUL on Windows.
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-compress.git
commit f2b68e96847fc6a3af50cab63f4619331633c3d9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 13 16:48:37 2022 -0500
In most IOUtil methods,the target may be null to simulate output to
dev/null on Linux and NUL on Windows.
Used a next commit.
---
.../java/org/apache/commons/compress/utils/IOUtils.java | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/utils/IOUtils.java b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
index a043b8e..528b858 100644
--- a/src/main/java/org/apache/commons/compress/utils/IOUtils.java
+++ b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
@@ -61,7 +61,7 @@ public final class IOUtils {
* @param input
* the InputStream to copy
* @param output
- * the target Stream
+ * the target, may be null to simulate output to dev/null on Linux and NUL on Windows
* @return the number of bytes copied
* @throws IOException
* if an error occurs
@@ -76,7 +76,7 @@ public final class IOUtils {
* @param input
* the InputStream to copy
* @param output
- * the target Stream
+ * the target, may be null to simulate output to dev/null on Linux and NUL on Windows
* @param buffersize
* the buffer size to use, must be bigger than 0
* @return the number of bytes copied
@@ -93,7 +93,9 @@ public final class IOUtils {
int n = 0;
long count=0;
while (-1 != (n = input.read(buffer))) {
- output.write(buffer, 0, n);
+ if (output != null) {
+ output.write(buffer, 0, n);
+ }
count += n;
}
return count;
@@ -309,7 +311,7 @@ public final class IOUtils {
* @param len
* maximum amount of bytes to copy
* @param output
- * the target Stream
+ * the target, may be null to simulate output to dev/null on Linux and NUL on Windows
* @param buffersize
* the buffer size to use, must be bigger than 0
* @return the number of bytes copied
@@ -328,7 +330,9 @@ public final class IOUtils {
int n = 0;
long count = 0;
while (count < len && -1 != (n = input.read(buffer, 0, (int) Math.min(len - count, buffer.length)))) {
- output.write(buffer, 0, n);
+ if (output != null) {
+ output.write(buffer, 0, n);
+ }
count += n;
}
return count;