This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch 1.x
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git

commit 9b54a0353521f7a64f2000d6edaec5f93941d912
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Aug 25 11:55:36 2024 -0400

    Use try-with-resources
---
 .../commons/fileupload/DefaultFileItemTest.java    | 56 ++++++++++------------
 1 file changed, 26 insertions(+), 30 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java 
b/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java
index bc94355d..844f6601 100644
--- a/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java
+++ b/src/test/java/org/apache/commons/fileupload/DefaultFileItemTest.java
@@ -225,76 +225,72 @@ public class DefaultFileItemTest {
     /**
      * Test construction of content charset.
      */
+    @Test
     public void testContentCharSet() throws Exception {
         final FileItemFactory factory = createFactory(null);
 
         String teststr = constructString(SWISS_GERMAN_STUFF_UNICODE);
 
-        FileItem item =
-            factory.createItem(
+        FileItem item = factory.createItem(
                 "doesnotmatter",
                 "text/plain; charset=" + CHARSET_ISO88591,
                 true,
                 null);
-        OutputStream outstream = item.getOutputStream();
-        for (final int element : SWISS_GERMAN_STUFF_ISO8859_1) {
-            outstream.write(element);
+        try (OutputStream out = item.getOutputStream()) {
+            for (final int element : SWISS_GERMAN_STUFF_ISO8859_1) {
+                out.write(element);
+            }
         }
-        outstream.close();
         assertEquals(teststr, teststr, item.getString());
 
-        item =
-            factory.createItem(
+        item = factory.createItem(
                 "doesnotmatter",
                 "text/plain; charset=" + CHARSET_UTF8,
                 true,
                 null);
-        outstream = item.getOutputStream();
-        for (final int element : SWISS_GERMAN_STUFF_UTF8) {
-            outstream.write(element);
+        try (OutputStream out = item.getOutputStream()) {
+            for (final int element : SWISS_GERMAN_STUFF_UTF8) {
+                out.write(element);
+            }
         }
-        outstream.close();
         assertEquals(teststr, teststr, item.getString());
 
         teststr = constructString(RUSSIAN_STUFF_UNICODE);
 
-        item =
-            factory.createItem(
+        item = factory.createItem(
                 "doesnotmatter",
                 "text/plain; charset=" + CHARSET_KOI8_R,
                 true,
                 null);
-        outstream = item.getOutputStream();
-        for (final int element : RUSSIAN_STUFF_KOI8R) {
-            outstream.write(element);
+        try (OutputStream out = item.getOutputStream()) {
+            for (final int element : RUSSIAN_STUFF_KOI8R) {
+                out.write(element);
+            }
         }
-        outstream.close();
         assertEquals(teststr, teststr, item.getString());
 
-        item =
-            factory.createItem(
+        item = factory.createItem(
                 "doesnotmatter",
                 "text/plain; charset=" + CHARSET_WIN1251,
                 true,
                 null);
-        outstream = item.getOutputStream();
-        for (final int element : RUSSIAN_STUFF_WIN1251) {
-            outstream.write(element);
+        try (OutputStream out = item.getOutputStream()) {
+            for (final int element : RUSSIAN_STUFF_WIN1251) {
+                out.write(element);
+            }
         }
-        outstream.close();
         assertEquals(teststr, teststr, item.getString());
 
-        item =
-            factory.createItem(
+        item = factory.createItem(
                 "doesnotmatter",
                 "text/plain; charset=" + CHARSET_UTF8,
                 true,
                 null);
-        outstream = item.getOutputStream();
-        for (final int element : RUSSIAN_STUFF_UTF8) {
-            outstream.write(element);
+        try (OutputStream out = item.getOutputStream()) {
+            for (final int element : RUSSIAN_STUFF_UTF8) {
+                out.write(element);
+            }
         }
-        outstream.close();
         assertEquals(teststr, teststr, item.getString());
     }
 

Reply via email to