Example usage for org.eclipse.jgit.lib ObjectLoader ObjectLoader

List of usage examples for org.eclipse.jgit.lib ObjectLoader ObjectLoader

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ObjectLoader ObjectLoader.

Prototype

ObjectLoader

Source Link

Usage

From source file:org.gitective.tests.BlobUtilsTest.java

License:Open Source License

/**
 * Test getting blob content with object load that throws a
 * {@link LargeObjectException}/* w  w  w .  j av  a 2 s . c  o  m*/
 *
 * @throws Exception
 */
@Test
public void largeLoader() throws Exception {
    add("test.txt", "content");
    final AtomicReference<AbbreviatedObjectId> blob = new AtomicReference<AbbreviatedObjectId>();
    CommitDiffFilter diffs = new CommitDiffFilter() {

        public boolean include(RevCommit commit, Collection<DiffEntry> diffs) {
            blob.set(diffs.iterator().next().getNewId());
            return true;
        }

    };
    new CommitFinder(testRepo).setFilter(diffs).find();
    assertNotNull(blob.get());

    Repository repo = new FileRepository(testRepo) {

        public ObjectLoader open(AnyObjectId objectId, int typeHint)
                throws MissingObjectException, IncorrectObjectTypeException, IOException {
            final ObjectLoader loader = super.open(objectId, typeHint);
            return new ObjectLoader() {

                public ObjectStream openStream() throws MissingObjectException, IOException {
                    return loader.openStream();
                }

                public int getType() {
                    return loader.getType();
                }

                public long getSize() {
                    return loader.getSize();
                }

                public byte[] getCachedBytes() throws LargeObjectException {
                    throw new LargeObjectException();
                }
            };
        }

    };
    assertEquals("content", BlobUtils.getContent(repo, blob.get().toObjectId()));
}