]> source.dussan.org Git - jgit.git/commitdiff
AutoCRLFInputStreamTest: Open auto-closeable resources in try-with-resource 68/118668/1
authorDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 5 Mar 2018 11:59:31 +0000 (20:59 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 5 Mar 2018 11:59:31 +0000 (20:59 +0900)
Change-Id: I427ab43a82861f7bc69b104e29dc4360048aec4e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java

index 83a53b9a6df727a4b38d4a136e1da8a027753043..1272e16173c76caf316ae5b95a3cecd6216f0fe7 100644 (file)
@@ -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));
                }
        }