diff options
Diffstat (limited to 'org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java')
-rw-r--r-- | org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java index 4ba2606fb3..cef81a062d 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.junit; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -180,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); } } @@ -250,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(); } } @@ -270,7 +263,7 @@ public abstract class JGitTestUtil { */ public static String read(final File file) throws IOException { final byte[] body = IO.readFully(file); - return new String(body, 0, body.length, "UTF-8"); + return new String(body, 0, body.length, UTF_8); } /** |