Skip to content

Commit 4117033

Browse files
committed
Refactor using new Supplier API
IOUtils.toString(IOSupplier<InputStream>, Charset[, IOSupplier<String>]). Refactor using new Supplier API org.apache.commons.io.file.PathUtils.copy(IOSupplier<InputStream>, Path, CopyOption...).
1 parent b21c2ac commit 4117033

6 files changed

Lines changed: 127 additions & 55 deletions

File tree

src/changes/changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@ The <action> type attribute can be add,update,fix,remove.
474474
<action dev="ggregory" type="add" due-to="Gary Gregory, maxxedev">
475475
Add PollingQueueInputStream and TakingQueueInputStream to replace QueueInputStream. See also #447.
476476
</action>
477+
<action dev="ggregory" type="add" due-to="Gary Gregory, maxxedev">
478+
Refactor using new Supplier API IOUtils.toString(IOSupplier&lt;InputStream&gt;, Charset[, IOSupplier&lt;String&gt;]).
479+
</action>
480+
<action dev="ggregory" type="add" due-to="Gary Gregory, maxxedev">
481+
Refactor using new Supplier API org.apache.commons.io.file.PathUtils.copy(IOSupplier&lt;InputStream&gt;, Path, CopyOption...).
482+
</action>
477483
<!-- UPDATE -->
478484
<action dev="kinow" type="update" due-to="Dependabot, Gary Gregory">
479485
Bump actions/cache from 2.1.6 to 3.0.10 #307, #337, #393.

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,11 +1059,9 @@ public static void copyToFile(final InputStream inputStream, final File file) th
10591059
* @throws IOException if an IO error occurs during copying
10601060
*/
10611061
public static void copyURLToFile(final URL source, final File destination) throws IOException {
1062-
try (InputStream stream = source.openStream()) {
1063-
final Path path = destination.toPath();
1064-
PathUtils.createParentDirectories(path);
1065-
Files.copy(stream, path, StandardCopyOption.REPLACE_EXISTING);
1066-
}
1062+
final Path path = destination.toPath();
1063+
PathUtils.createParentDirectories(path);
1064+
PathUtils.copy(source::openStream, path, StandardCopyOption.REPLACE_EXISTING);
10671065
}
10681066

10691067
/**
@@ -2597,9 +2595,7 @@ public static String readFileToString(final File file) throws IOException {
25972595
* @since 2.3
25982596
*/
25992597
public static String readFileToString(final File file, final Charset charsetName) throws IOException {
2600-
try (InputStream inputStream = Files.newInputStream(file.toPath())) {
2601-
return IOUtils.toString(inputStream, Charsets.toCharset(charsetName));
2602-
}
2598+
return IOUtils.toString(() -> Files.newInputStream(file.toPath()), Charsets.toCharset(charsetName));
26032599
}
26042600

26052601
/**

0 commit comments

Comments
 (0)