Skip to content

Commit 51f4de0

Browse files
author
Gary Gregory
committed
Use lambdas, in-line single use local variable, remove some whitespace.
1 parent 4c7a0d1 commit 51f4de0

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.nio.charset.Charset;
4646
import java.nio.file.Files;
4747
import java.util.ArrayList;
48+
import java.util.Arrays;
4849
import java.util.Collection;
4950
import java.util.List;
5051
import java.util.Objects;
@@ -521,11 +522,8 @@ public static void closeQuietly(final Closeable closeable) {
521522
* @see Throwable#addSuppressed(java.lang.Throwable)
522523
*/
523524
public static void closeQuietly(final Closeable... closeables) {
524-
if (closeables == null) {
525-
return;
526-
}
527-
for (final Closeable closeable : closeables) {
528-
closeQuietly(closeable);
525+
if (closeables != null) {
526+
Arrays.stream(closeables).forEach(IOUtils::closeQuietly);
529527
}
530528
}
531529

@@ -1105,10 +1103,8 @@ public static void copy(final InputStream input, final Writer writer, final Stri
11051103
@SuppressWarnings("resource") // streams are closed by the caller.
11061104
public static QueueInputStream copy(final java.io.ByteArrayOutputStream outputStream) throws IOException {
11071105
Objects.requireNonNull(outputStream, "outputStream");
1108-
11091106
final QueueInputStream in = new QueueInputStream();
11101107
outputStream.writeTo(in.newQueueOutputStream());
1111-
11121108
return in;
11131109
}
11141110

@@ -2198,11 +2194,9 @@ public static URL resourceToURL(final String name, final ClassLoader classLoader
21982194
// What about the thread context class loader?
21992195
// What about the system class loader?
22002196
final URL resource = classLoader == null ? IOUtils.class.getResource(name) : classLoader.getResource(name);
2201-
22022197
if (resource == null) {
22032198
throw new IOException("Resource not found: " + name);
22042199
}
2205-
22062200
return resource;
22072201
}
22082202

@@ -2559,11 +2553,9 @@ public static byte[] toByteArray(final InputStream input, final int size) throws
25592553
* @since 2.1
25602554
*/
25612555
public static byte[] toByteArray(final InputStream input, final long size) throws IOException {
2562-
25632556
if (size > Integer.MAX_VALUE) {
25642557
throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);
25652558
}
2566-
25672559
return toByteArray(input, (int) size);
25682560
}
25692561

@@ -2873,8 +2865,7 @@ public static InputStream toInputStream(final String input, final Charset charse
28732865
* @since 1.1
28742866
*/
28752867
public static InputStream toInputStream(final String input, final String charsetName) {
2876-
final byte[] bytes = input.getBytes(Charsets.toCharset(charsetName));
2877-
return new ByteArrayInputStream(bytes);
2868+
return new ByteArrayInputStream(input.getBytes(Charsets.toCharset(charsetName)));
28782869
}
28792870

28802871
/**
@@ -3662,7 +3653,6 @@ public static Writer writer(final Appendable appendable) {
36623653
* Instances should NOT be constructed in standard programming.
36633654
*/
36643655
public IOUtils() { //NOSONAR
3665-
36663656
}
36673657

36683658
}

0 commit comments

Comments
 (0)