LargePackedWholeObject: Refactor to open DfsReader in try-with-resource
Change-Id: Ia9557e6c1ab230dbe2e94e025a49e93159d8658c Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
aaf4b35557
commit
b0ac5f9c89
|
@ -104,32 +104,26 @@ public byte[] getCachedBytes() throws LargeObjectException {
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public ObjectStream openStream() throws MissingObjectException, IOException {
|
public ObjectStream openStream() throws MissingObjectException, IOException {
|
||||||
DfsReader ctx = db.newReader();
|
|
||||||
InputStream in;
|
InputStream in;
|
||||||
try {
|
try (DfsReader ctx = db.newReader()) {
|
||||||
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 {
|
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);
|
ObjectId obj = pack.getReverseIdx(ctx).findObject(objectOffset);
|
||||||
return ctx.open(obj, type).openStream();
|
return ctx.open(obj, type).openStream();
|
||||||
} finally {
|
|
||||||
ctx.close();
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
ctx.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Align buffer to inflater size, at a larger than default block.
|
// Align buffer to inflater size, at a larger than default block.
|
||||||
// This reduces the number of context switches from the
|
// This reduces the number of context switches from the
|
||||||
// caller down into the pack stream inflation.
|
// caller down into the pack stream inflation.
|
||||||
int bufsz = 8192;
|
int bufsz = 8192;
|
||||||
in = new BufferedInputStream(
|
in = new BufferedInputStream(
|
||||||
new InflaterInputStream(in, ctx.inflater(), bufsz),
|
new InflaterInputStream(in, ctx.inflater(), bufsz), bufsz);
|
||||||
bufsz);
|
return new ObjectStream.Filter(type, size, in);
|
||||||
return new ObjectStream.Filter(type, size, in);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue