final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
write(id, compressStandardFormat(type, data));
ObjectLoader ol;
{
FileInputStream fs = new FileInputStream(path(id));
try {
ol = UnpackedObject.open(fs, path(id), id, wc);
} finally {
fs.close();
}
}
assertNotNull("created loader", ol);
assertEquals(type, ol.getType());
assertEquals(data.length, ol.getSize());
assertTrue("is large", ol.isLarge());
try {
ol.getCachedBytes();
fail("Should have thrown LargeObjectException");
} catch (LargeObjectException tooBig) {
assertEquals(MessageFormat.format(
JGitText.get().largeObjectException, id.name()), tooBig
.getMessage());
}
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(type, in.getType());
assertEquals(data.length, in.getSize());
byte[] data2 = new byte[data.length];
IO.readFully(in, data2, 0, data.length);