commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1753725 - /commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
Date Thu, 21 Jul 2016 19:17:50 GMT
Author: ggregory
Date: Thu Jul 21 19:17:49 2016
New Revision: 1753725

URL: http://svn.apache.org/viewvc?rev=1753725&view=rev
Log:
Fix compiler warnings, use try-with-resources.

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java?rev=1753725&r1=1753724&r2=1753725&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java Thu Jul 21 19:17:49
2016
@@ -135,11 +135,11 @@ public class IOUtils {
 
     static {
         // avoid security issues
-        final StringBuilderWriter buf = new StringBuilderWriter(4);
-        final PrintWriter out = new PrintWriter(buf);
-        out.println();
-        LINE_SEPARATOR = buf.toString();
-        out.close();
+        try (final StringBuilderWriter buf = new StringBuilderWriter(4); 
+                final PrintWriter out = new PrintWriter(buf)) {
+            out.println();
+            LINE_SEPARATOR = buf.toString();
+        }
     }
 
     /**
@@ -762,9 +762,10 @@ public class IOUtils {
      * @throws IOException          if an I/O error occurs
      */
     public static byte[] toByteArray(final InputStream input) throws IOException {
-        final ByteArrayOutputStream output = new ByteArrayOutputStream();
-        copy(input, output);
-        return output.toByteArray();
+        try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) {
+            copy(input, output);
+            return output.toByteArray();
+        }
     }
 
     /**
@@ -864,9 +865,10 @@ public class IOUtils {
      * @since 2.3
      */
     public static byte[] toByteArray(final Reader input, final Charset encoding) throws IOException
{
-        final ByteArrayOutputStream output = new ByteArrayOutputStream();
-        copy(input, output, encoding);
-        return output.toByteArray();
+        try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) {
+            copy(input, output, encoding);
+            return output.toByteArray();
+        }
     }
 
     /**
@@ -1079,9 +1081,10 @@ public class IOUtils {
      * @since 2.3
      */
     public static String toString(final InputStream input, final Charset encoding) throws
IOException {
-        final StringBuilderWriter sw = new StringBuilderWriter();
-        copy(input, sw, encoding);
-        return sw.toString();
+        try (final StringBuilderWriter sw = new StringBuilderWriter()) {
+            copy(input, sw, encoding);
+            return sw.toString();
+        }
     }
 
     /**
@@ -1120,9 +1123,10 @@ public class IOUtils {
      * @throws IOException          if an I/O error occurs
      */
     public static String toString(final Reader input) throws IOException {
-        final StringBuilderWriter sw = new StringBuilderWriter();
-        copy(input, sw);
-        return sw.toString();
+        try (final StringBuilderWriter sw = new StringBuilderWriter()) {
+            copy(input, sw);
+            return sw.toString();
+        }
     }
 
     /**



Mime
View raw message