summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-06 17:37:22 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-03-06 17:37:22 +0900
commitc6ea82b9cc1d42f55d571e5f85c9572e09de30a4 (patch)
tree99b8da26f1820e1da1db6e0faa201c1b4bac1f97
parente53edce867a5ff8e2d4e914b5debb74a6e10aec3 (diff)
downloadjgit-c6ea82b9cc1d42f55d571e5f85c9572e09de30a4.tar.gz
jgit-c6ea82b9cc1d42f55d571e5f85c9572e09de30a4.zip
GetTextTest: Open InputStream in try-with-resource
Change-Id: I3b68686de2d852b1f0b19c267a4e527229b40316 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java26
1 files changed, 10 insertions, 16 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
index d376f99517..65375c7ae0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
@@ -123,28 +123,24 @@ public class GetTextTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
private String readTestPatchFile(final Charset cs) throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final InputStreamReader r = new InputStreamReader(in, cs);
char[] tmp = new char[2048];
final StringBuilder s = new StringBuilder();
@@ -152,8 +148,6 @@ public class GetTextTest {
while ((n = r.read(tmp)) > 0)
s.append(tmp, 0, n);
return s.toString();
- } finally {
- in.close();
}
}
}