public ObjectLoader open(AnyObjectId objectId, int typeHint)
throws IOException {
if (objectMap == null)
return ctx.open(objectId, typeHint);
PackedObjectInfo obj = objectMap.get(objectId);
if (obj == null)
return ctx.open(objectId, typeHint);
byte[] buf = buffer();
int cnt = packOut.read(obj.getOffset(), buf, 0, 20);
if (cnt <= 0)
throw new EOFException(DfsText.get().unexpectedEofInPack);
int c = buf[0] & 0xff;
int type = (c >> 4) & 7;
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA)
throw new IOException(MessageFormat.format(
DfsText.get().cannotReadBackDelta, Integer.toString(type)));
long sz = c & 0x0f;
int ptr = 1;
int shift = 4;
while ((c & 0x80) != 0) {
if (ptr >= cnt)
throw new EOFException(DfsText.get().unexpectedEofInPack);
c = buf[ptr++] & 0xff;
sz += ((long) (c & 0x7f)) << shift;
shift += 7;
}
long zpos = obj.getOffset() + ptr;
if (sz < ctx.getStreamFileThreshold()) {
byte[] data = inflate(obj, zpos, (int) sz);
if (data != null)
return new ObjectLoader.SmallObject(type, data);
}
return new StreamLoader(obj.copy(), type, sz, packKey, zpos);
}