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-compress.git
The following commit(s) were added to refs/heads/master by this push:
new cf88717b Use try-with-resources
cf88717b is described below
commit cf88717b884f297c79a82d0067f261c7c7a873f1
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Nov 4 06:54:17 2023 -0400
Use try-with-resources
---
.../compress/archivers/zip/UTF8ZipFilesTest.java | 39 ++++++----------------
1 file changed, 10 insertions(+), 29 deletions(-)
diff --git
a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
index b933502d..0ac8b8f2 100644
---
a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
@@ -188,12 +188,8 @@ public class UTF8ZipFilesTest extends AbstractTestCase {
@Test
public void testRawNameReadFromZipFile() throws IOException {
final File archive = getFile("utf8-7zip-test.zip");
- ZipFile zf = null;
- try {
- zf = new ZipFile(archive, CP437, false);
+ try (ZipFile zf = new ZipFile(archive, CP437, false)) {
assertRawNameOfAcsiiTxt(zf.getEntry(ASCII_TXT));
- } finally {
- ZipFile.closeQuietly(zf);
}
}
@@ -205,14 +201,10 @@ public class UTF8ZipFilesTest extends AbstractTestCase {
@Test
public void testRead7ZipArchive() throws IOException {
final File archive = getFile("utf8-7zip-test.zip");
- ZipFile zf = null;
- try {
- zf = new ZipFile(archive, CP437, false);
+ try (ZipFile zf = new ZipFile(archive, CP437, false)) {
assertNotNull(zf.getEntry(ASCII_TXT));
assertNotNull(zf.getEntry(EURO_FOR_DOLLAR_TXT));
assertNotNull(zf.getEntry(OIL_BARREL_TXT));
- } finally {
- ZipFile.closeQuietly(zf);
}
}
@@ -231,20 +223,15 @@ public class UTF8ZipFilesTest extends AbstractTestCase {
@Test
public void testReadWinZipArchive() throws IOException {
final File archive = getFile("utf8-winzip-test.zip");
- ZipFile zf = null;
- try {
- // fix for test fails on Windows with default charset that is not
UTF-8
- String encoding = null;
- if (Charset.defaultCharset() != UTF_8) {
- encoding = UTF_8.name();
- }
-
- zf = new ZipFile(archive, encoding, true);
+ // fix for test fails on Windows with default charset that is not UTF-8
+ String encoding = null;
+ if (Charset.defaultCharset() != UTF_8) {
+ encoding = UTF_8.name();
+ }
+ try (ZipFile zf = new ZipFile(archive, encoding, true)) {
assertCanRead(zf, ASCII_TXT);
assertCanRead(zf, EURO_FOR_DOLLAR_TXT);
assertCanRead(zf, OIL_BARREL_TXT);
- } finally {
- ZipFile.closeQuietly(zf);
}
}
@@ -300,24 +287,18 @@ public class UTF8ZipFilesTest extends AbstractTestCase {
public void testUtf8Interoperability() throws IOException {
final File file1 = getFile("utf8-7zip-test.zip");
final File file2 = getFile("utf8-winzip-test.zip");
-
testFile(file1, CP437);
testFile(file2, CP437);
-
}
@Test
public void testZipArchiveInputStreamReadsUnicodeFields() throws
IOException {
final File file = createTempFile("unicode-test", ".zip");
- ZipFile zf = null;
- try {
- createTestFile(file, CharsetNames.US_ASCII, false, true);
- zf = new ZipFile(file, CharsetNames.US_ASCII, true);
+ createTestFile(file, CharsetNames.US_ASCII, false, true);
+ try (ZipFile zf = new ZipFile(file, CharsetNames.US_ASCII, true)) {
assertNotNull(zf.getEntry(ASCII_TXT));
assertNotNull(zf.getEntry(EURO_FOR_DOLLAR_TXT));
assertNotNull(zf.getEntry(OIL_BARREL_TXT));
- } finally {
- ZipFile.closeQuietly(zf);
}
}