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.
@@ -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))) {
+ 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)))) {
+ if (output != null) {
output.write(buffer, 0, n);
+ }
count += n;
}
return count;
