From ed9ede3446f0c95e80eb6feb1dec5dfa698184a9 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 14 Mar 2018 09:35:08 +0900 Subject: [PATCH] ShowPackDelta: Refactor to use try-with-resource Remove the resource warning suppression and refactor the code to open the TemporaryBuffer and InflaterInputStream in a try-with-resource. Change-Id: I3082e5ac7565c5000d5a4364f750dd0a0952fc6e Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/pgm/debug/ShowPackDelta.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java index bbc1b0f33..f39ecbecf 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java @@ -125,12 +125,13 @@ class ShowPackDelta extends TextBuiltin { ptr++; ptr++; - @SuppressWarnings("resource" /* java 7 */) - TemporaryBuffer.Heap raw = new TemporaryBuffer.Heap(bufArray.length); - InflaterInputStream inf = new InflaterInputStream( - new ByteArrayInputStream(bufArray, ptr, bufArray.length)); - raw.copy(inf); - inf.close(); - return raw.toByteArray(); + try (TemporaryBuffer.Heap raw = new TemporaryBuffer.Heap( + bufArray.length); + InflaterInputStream inf = new InflaterInputStream( + new ByteArrayInputStream(bufArray, ptr, + bufArray.length))) { + raw.copy(inf); + return raw.toByteArray(); + } } }