Skip to content
Permalink
Browse files
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.
  • Loading branch information
garydgregory committed Feb 13, 2022
1 parent 5b3c8f7 commit f2b68e96847fc6a3af50cab63f4619331633c3d9
Showing 1 changed file with 9 additions and 5 deletions.
@@ -61,7 +61,7 @@ private 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 static long copy(final InputStream input, final OutputStream output) thro
* @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 static long copy(final InputStream input, final OutputStream output, fina
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 static long copyRange(final InputStream input, final long len, final Outp
* @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 static long copyRange(final InputStream input, final long len, final Outp
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;

0 comments on commit f2b68e9

Please sign in to comment.