summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-07 08:30:52 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-03-07 09:04:36 +0900
commitf91ce7faad1ffdb31c1f0a801b0c9e43bb8ab260 (patch)
tree801291aed95906444670b7dbdb29a9aac3ba1cc6 /org.eclipse.jgit.junit
parent0b4e781f7c2c46d0abe0437c63d9656bc1842cd0 (diff)
downloadjgit-f91ce7faad1ffdb31c1f0a801b0c9e43bb8ab260.tar.gz
jgit-f91ce7faad1ffdb31c1f0a801b0c9e43bb8ab260.zip
JGitTestUtil: Open auto-closeable resources in try-with-resource
Change-Id: Ibc8dd8509109708628e5189888fa528add486452 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java23
1 files changed, 7 insertions, 16 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 782d402f92..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
@@ -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();
}
}