]> source.dussan.org Git - jgit.git/commitdiff
JGitTestUtil: Open auto-closeable resources in try-with-resource 35/118835/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 6 Mar 2018 23:30:52 +0000 (08:30 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 7 Mar 2018 00:04:36 +0000 (09:04 +0900)
Change-Id: Ibc8dd8509109708628e5189888fa528add486452
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java

index 782d402f9207d0d1c9c91eabb54271c1bc77ca94..cef81a062d4e6b952d5f7a773fd0c07a148fc97c 100644 (file)
@@ -182,18 +182,11 @@ public abstract class JGitTestUtil {
                URL url = cl().getResource(CLASSPATH_TO_RESOURCES + name);
                if (url == null)
                        throw new FileNotFoundException(name);
-               InputStream in = url.openStream();
-               try {
-                       FileOutputStream out = new FileOutputStream(dest);
-                       try {
-                               byte[] buf = new byte[4096];
-                               for (int n; (n = in.read(buf)) > 0;)
-                                       out.write(buf, 0, n);
-                       } finally {
-                               out.close();
-                       }
-               } finally {
-                       in.close();
+               try (InputStream in = url.openStream();
+                               FileOutputStream out = new FileOutputStream(dest)) {
+                       byte[] buf = new byte[4096];
+                       for (int n; (n = in.read(buf)) > 0;)
+                               out.write(buf, 0, n);
                }
        }
 
@@ -252,11 +245,9 @@ public abstract class JGitTestUtil {
        public static void write(final File f, final String body)
                        throws IOException {
                FileUtils.mkdirs(f.getParentFile(), true);
-               Writer w = new OutputStreamWriter(new FileOutputStream(f), UTF_8);
-               try {
+               try (Writer w = new OutputStreamWriter(new FileOutputStream(f),
+                               UTF_8)) {
                        w.write(body);
-               } finally {
-                       w.close();
                }
        }