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/12/04 21:08:19 UTC

[commons-vfs] branch master updated: 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-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new d4a3cdbf Use try-with-resources
d4a3cdbf is described below

commit d4a3cdbf9f3dc97a018548cec29b47d60bc9d246
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 4 16:08:14 2022 -0500

    Use try-with-resources
---
 .../test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java
index 606557fd..68e041b6 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/gzip/GzipTest.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.commons.vfs2.FileContent;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemManager;
 import org.apache.commons.vfs2.VFS;
@@ -31,8 +32,8 @@ public class GzipTest {
 
     @Test
     public void testCreateGzipFileSystem() throws IOException {
-
         final File gzFile = new File("src/test/resources/test-data/好.txt.gz");
+        @SuppressWarnings("resource") // global
         FileSystemManager manager = VFS.getManager();
 
         try (FileObject localFileObject = manager.resolveFile(gzFile.getAbsolutePath());
@@ -42,8 +43,9 @@ public class GzipTest {
             Assertions.assertTrue(gzFileObjectDir.isFolder());
             Assertions.assertTrue(gzFileObject instanceof GzipFileObject);
             Assertions.assertFalse(gzFileObject.isFolder());
-            String content = gzFileObject.getContent().getString(StandardCharsets.UTF_8);
-            Assertions.assertEquals("aaa", content);
+            try (FileContent content = gzFileObject.getContent()) {
+                Assertions.assertEquals("aaa", content.getString(StandardCharsets.UTF_8));
+            }
         }
     }
 }