diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-05 20:59:31 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-05 20:59:31 +0900 |
commit | fd20f8c6579e3c90c598879f753c635fe5a54699 (patch) | |
tree | f37adc758278c43d5323879fb582bb0136a9272c /org.eclipse.jgit.test | |
parent | 8ab6f78d02f5b63837e6188c201e5fba28c7623d (diff) | |
download | jgit-fd20f8c6579e3c90c598879f753c635fe5a54699.tar.gz jgit-fd20f8c6579e3c90c598879f753c635fe5a54699.zip |
AutoCRLFInputStreamTest: Open auto-closeable resources in try-with-resource
Change-Id: I427ab43a82861f7bc69b104e29dc4360048aec4e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java index 83a53b9a6d..1272e16173 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java @@ -93,25 +93,24 @@ public class AutoCRLFInputStreamTest { byte[] expectBytes = expect.getBytes(); for (int i = 0; i < 5; ++i) { byte[] buf = new byte[i]; - ByteArrayInputStream bis = new ByteArrayInputStream(inbytes); - InputStream in = new AutoCRLFInputStream(bis, true); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - if (i > 0) { - int n; - while ((n = in.read(buf)) >= 0) { - out.write(buf, 0, n); + try (ByteArrayInputStream bis = new ByteArrayInputStream(inbytes); + InputStream in = new AutoCRLFInputStream(bis, true); + ByteArrayOutputStream out = new ByteArrayOutputStream()) { + if (i > 0) { + int n; + while ((n = in.read(buf)) >= 0) { + out.write(buf, 0, n); + } + } else { + int c; + while ((c = in.read()) != -1) + out.write(c); } - } else { - int c; - while ((c = in.read()) != -1) - out.write(c); + out.flush(); + byte[] actualBytes = out.toByteArray(); + Assert.assertEquals("bufsize=" + i, encode(expectBytes), + encode(actualBytes)); } - out.flush(); - in.close(); - out.close(); - byte[] actualBytes = out.toByteArray(); - Assert.assertEquals("bufsize=" + i, encode(expectBytes), - encode(actualBytes)); } } |