From b0ac5f9c8907a4034612543a92eb465e88a9c6f2 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 11 Apr 2018 13:59:00 +0900 Subject: [PATCH] LargePackedWholeObject: Refactor to open DfsReader in try-with-resource Change-Id: Ia9557e6c1ab230dbe2e94e025a49e93159d8658c Signed-off-by: David Pursehouse --- .../storage/dfs/LargePackedWholeObject.java | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java index fa2c5291c6..b6e9d319aa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java @@ -104,32 +104,26 @@ final class LargePackedWholeObject extends ObjectLoader { /** {@inheritDoc} */ @Override public ObjectStream openStream() throws MissingObjectException, IOException { - DfsReader ctx = db.newReader(); InputStream in; - try { - in = new PackInputStream(pack, objectOffset + headerLength, ctx); - } catch (IOException packGone) { - // If the pack file cannot be pinned into the cursor, it - // probably was repacked recently. Go find the object - // again and open the stream from that location instead. - // + try (DfsReader ctx = db.newReader()) { try { + in = new PackInputStream(pack, objectOffset + headerLength, ctx); + } catch (IOException packGone) { + // If the pack file cannot be pinned into the cursor, it + // probably was repacked recently. Go find the object + // again and open the stream from that location instead. + // ObjectId obj = pack.getReverseIdx(ctx).findObject(objectOffset); return ctx.open(obj, type).openStream(); - } finally { - ctx.close(); } - } finally { - ctx.close(); - } - // Align buffer to inflater size, at a larger than default block. - // This reduces the number of context switches from the - // caller down into the pack stream inflation. - int bufsz = 8192; - in = new BufferedInputStream( - new InflaterInputStream(in, ctx.inflater(), bufsz), - bufsz); - return new ObjectStream.Filter(type, size, in); + // Align buffer to inflater size, at a larger than default block. + // This reduces the number of context switches from the + // caller down into the pack stream inflation. + int bufsz = 8192; + in = new BufferedInputStream( + new InflaterInputStream(in, ctx.inflater(), bufsz), bufsz); + return new ObjectStream.Filter(type, size, in); + } } } -- 2.39.5