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/08/13 13:33:49 UTC
[commons-io] 01/03: Use try-with-resources
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-io.git
commit d9fb09170f381a80a400d93d8c7c729590f59d5e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 13 08:29:04 2022 -0400
Use try-with-resources
---
.../java/org/apache/commons/io/FileUtilsTest.java | 36 +++++-----------------
1 file changed, 8 insertions(+), 28 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index afda381b..a96b468f 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -1645,26 +1645,17 @@ public class FileUtilsTest extends AbstractTempDirTest {
throw new IOException("Cannot create file " + oldFile
+ " as the parent directory does not exist");
}
- final OutputStream output1 =
- new BufferedOutputStream(Files.newOutputStream(oldFile.toPath()));
- try {
+ try (final OutputStream output1 = new BufferedOutputStream(Files.newOutputStream(oldFile.toPath()))) {
TestUtils.generateTestData(output1, 0);
- } finally {
- IOUtils.closeQuietly(output1);
}
do {
TestUtils.sleepQuietly(1000);
if (!reference.getParentFile().exists()) {
- throw new IOException("Cannot create file " + reference
- + " as the parent directory does not exist");
+ throw new IOException("Cannot create file " + reference + " as the parent directory does not exist");
}
- final OutputStream output =
- new BufferedOutputStream(Files.newOutputStream(reference.toPath()));
- try {
+ try (final OutputStream output = new BufferedOutputStream(Files.newOutputStream(reference.toPath()))) {
TestUtils.generateTestData(output, 0);
- } finally {
- IOUtils.closeQuietly(output);
}
} while (getLastModifiedMillis(oldFile) == getLastModifiedMillis(reference));
@@ -1689,12 +1680,8 @@ public class FileUtilsTest extends AbstractTempDirTest {
throw new IOException("Cannot create file " + newFile
+ " as the parent directory does not exist");
}
- final OutputStream output =
- new BufferedOutputStream(Files.newOutputStream(newFile.toPath()));
- try {
+ try (final OutputStream output = new BufferedOutputStream(Files.newOutputStream(newFile.toPath()))) {
TestUtils.generateTestData(output, 0);
- } finally {
- IOUtils.closeQuietly(output);
}
} while (getLastModifiedMillis(reference) == getLastModifiedMillis(newFile));
@@ -2353,22 +2340,15 @@ public class FileUtilsTest extends AbstractTempDirTest {
final File testFile1 = new File(tempDirFile, "testMoveFileFile1");
final File testFile2 = new File(tempDirFile, "testMoveFileFile2");
if (!testFile1.getParentFile().exists()) {
- throw new IOException("Cannot create file " + testFile1
- + " as the parent directory does not exist");
+ throw new IOException("Cannot create file " + testFile1 + " as the parent directory does not exist");
}
- final BufferedOutputStream output1 =
- new BufferedOutputStream(Files.newOutputStream(testFile1.toPath()));
- try {
+ try (final BufferedOutputStream output1 = new BufferedOutputStream(Files.newOutputStream(testFile1.toPath()))) {
TestUtils.generateTestData(output1, 0);
- } finally {
- IOUtils.closeQuietly(output1);
}
if (!testFile2.getParentFile().exists()) {
- throw new IOException("Cannot create file " + testFile2
- + " as the parent directory does not exist");
+ throw new IOException("Cannot create file " + testFile2 + " as the parent directory does not exist");
}
- final BufferedOutputStream output =
- new BufferedOutputStream(Files.newOutputStream(testFile2.toPath()));
+ final BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(testFile2.toPath()));
try {
TestUtils.generateTestData(output, 0);
} finally {