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 83a53b9a6..1272e1617 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 @@ private void assertNoCrLfHelper(String expect, String input) 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)); } }