]> source.dussan.org Git - jgit.git/commitdiff
DirCacheCheckoutTest: Open FileInputStream in try-with-resource 40/118740/3
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 6 Mar 2018 01:44:23 +0000 (10:44 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 6 Mar 2018 07:56:12 +0000 (16:56 +0900)
Change-Id: I3ceef36803752a19a4d74910b4db26c01279fd99
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

index 4d42bd19c5eb97bef8f381b3c0baa97d774b311a..0412242ebf67044d9fc23c9a6c95c7d9ef84604b 100644 (file)
@@ -1923,18 +1923,20 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
                                if (file.isFile()) {
                                        assertNotNull("found unexpected file for path " + path
                                                        + " in workdir", expectedValue);
-                                       FileInputStream is = new FileInputStream(file);
-                                       byte[] buffer = new byte[(int) file.length()];
-                                       int offset = 0;
-                                       int numRead = 0;
-                                       while (offset < buffer.length
-                                                       && (numRead = is.read(buffer, offset, buffer.length
-                                                                       - offset)) >= 0) {
-                                               offset += numRead;
+                                       try (FileInputStream is = new FileInputStream(file)) {
+                                               byte[] buffer = new byte[(int) file.length()];
+                                               int offset = 0;
+                                               int numRead = 0;
+                                               while (offset < buffer.length
+                                                               && (numRead = is.read(buffer, offset,
+                                                                               buffer.length - offset)) >= 0) {
+                                                       offset += numRead;
+                                               }
+                                               assertArrayEquals(
+                                                               "unexpected content for path " + path
+                                                                               + " in workDir. ",
+                                                               buffer, i.get(path).getBytes());
                                        }
-                                       is.close();
-                                       assertArrayEquals("unexpected content for path " + path
-                                                       + " in workDir. ", buffer, i.get(path).getBytes());
                                        nrFiles++;
                                } else if (file.isDirectory()) {
                                        String[] files = file.list();