diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-05 17:15:04 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-05 17:15:04 +0900 |
commit | fa9ee83697d1a8b4e6ffe90e8d488269cd5599f3 (patch) | |
tree | 7ca43e9e92462638ae00451fe6c857d56606dfd4 /org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java | |
parent | 99c187a5da1651c404f550cf449a65eaaf390b75 (diff) | |
download | jgit-fa9ee83697d1a8b4e6ffe90e8d488269cd5599f3.tar.gz jgit-fa9ee83697d1a8b4e6ffe90e8d488269cd5599f3.zip |
WalkRemoteObjectDatabase: Open auto-closeable resources in try-with-resource
Change-Id: Ie4f67ca8cab1031089782f202588b08cc157dd79
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java index a0ad2f3662..965be509cd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java @@ -264,11 +264,8 @@ abstract class WalkRemoteObjectDatabase { * failed, possibly due to permissions or remote disk full, etc. */ void writeFile(final String path, final byte[] data) throws IOException { - final OutputStream os = writeFile(path, null, null); - try { + try (OutputStream os = writeFile(path, null, null)) { os.write(data); - } finally { - os.close(); } } @@ -394,8 +391,7 @@ abstract class WalkRemoteObjectDatabase { */ Collection<WalkRemoteObjectDatabase> readAlternates(final String listPath) throws IOException { - final BufferedReader br = openReader(listPath); - try { + try (BufferedReader br = openReader(listPath)) { final Collection<WalkRemoteObjectDatabase> alts = new ArrayList<>(); for (;;) { String line = br.readLine(); @@ -406,8 +402,6 @@ abstract class WalkRemoteObjectDatabase { alts.add(openAlternate(line)); } return alts; - } finally { - br.close(); } } @@ -422,14 +416,8 @@ abstract class WalkRemoteObjectDatabase { */ protected void readPackedRefs(final Map<String, Ref> avail) throws TransportException { - try { - final BufferedReader br = openReader(ROOT_DIR - + Constants.PACKED_REFS); - try { - readPackedRefsImpl(avail, br); - } finally { - br.close(); - } + try (BufferedReader br = openReader(ROOT_DIR + Constants.PACKED_REFS)) { + readPackedRefsImpl(avail, br); } catch (FileNotFoundException notPacked) { // Perhaps it wasn't worthwhile, or is just an older repository. } catch (IOException e) { |