in.reset();
Inflater inf = wc.inflater();
InputStream zIn = inflate(in, inf);
int avail = readSome(zIn, hdr, 0, 64);
if (avail < 5)
throw new CorruptObjectException(id,
JGitText.get().corruptObjectNoHeader);
final MutableInteger p = new MutableInteger();
int type = Constants.decodeTypeString(id, hdr, (byte) ' ', p);
long size = RawParseUtils.parseLongBase10(hdr, p.value, p);
if (size < 0)
throw new CorruptObjectException(id,
JGitText.get().corruptObjectNegativeSize);
if (hdr[p.value++] != 0)
throw new CorruptObjectException(id,
JGitText.get().corruptObjectGarbageAfterSize);
if (path == null && Integer.MAX_VALUE < size) {
LargeObjectException.ExceedsByteArrayLimit e;
e = new LargeObjectException.ExceedsByteArrayLimit();
e.setObjectId(id);
throw e;
}
if (size < wc.getStreamFileThreshold() || path == null) {
byte[] data = new byte[(int) size];
int n = avail - p.value;
if (n > 0)
System.arraycopy(hdr, p.value, data, 0, n);
IO.readFully(zIn, data, n, data.length - n);
checkValidEndOfStream(in, inf, id, hdr);
return new ObjectLoader.SmallObject(type, data);
}
return new LargeObject(type, size, path, id, wc.db);
} else {
readSome(in, hdr, 2, 18);
int c = hdr[0] & 0xff;
int type = (c >> 4) & 7;
long size = c & 15;
int shift = 4;
int p = 1;
while ((c & 0x80) != 0) {
c = hdr[p++] & 0xff;
size += (c & 0x7f) << shift;
shift += 7;
}
switch (type) {
case Constants.OBJ_COMMIT:
case Constants.OBJ_TREE:
case Constants.OBJ_BLOB:
case Constants.OBJ_TAG:
// Acceptable types for a loose object.
break;
default:
throw new CorruptObjectException(id,
JGitText.get().corruptObjectInvalidType);
}
if (path == null && Integer.MAX_VALUE < size) {
LargeObjectException.ExceedsByteArrayLimit e;
e = new LargeObjectException.ExceedsByteArrayLimit();
e.setObjectId(id);
throw e;
}
if (size < wc.getStreamFileThreshold() || path == null) {
in.reset();
IO.skipFully(in, p);
Inflater inf = wc.inflater();
InputStream zIn = inflate(in, inf);
byte[] data = new byte[(int) size];
IO.readFully(zIn, data, 0, data.length);
checkValidEndOfStream(in, inf, id, hdr);
return new ObjectLoader.SmallObject(type, data);
}
return new LargeObject(type, size, path, id, wc.db);
}
} catch (ZipException badStream) {
throw new CorruptObjectException(id,
JGitText.get().corruptObjectBadStream);
}
}