List of usage examples for org.eclipse.jgit.revwalk RevWalk lookupAny
@NonNull public RevObject lookupAny(AnyObjectId id, int type)
From source file:org.kie.commons.java.nio.fs.jgit.util.JGitUtil.java
License:Apache License
public static InputStream resolveInputStream(final Git git, final String treeRef, final String path) { checkNotNull("git", git); checkNotEmpty("treeRef", treeRef); checkNotEmpty("path", path); final String gitPath = fixPath(path); RevWalk rw = null; TreeWalk tw = null;/*www.j av a 2s . c o m*/ try { final ObjectId tree = git.getRepository().resolve(treeRef + "^{tree}"); rw = new RevWalk(git.getRepository()); tw = new TreeWalk(git.getRepository()); tw.setFilter(createFromStrings(singleton(gitPath))); tw.reset(tree); while (tw.next()) { if (tw.isSubtree() && !gitPath.equals(tw.getPathString())) { tw.enterSubtree(); continue; } final ObjectId entid = tw.getObjectId(0); final FileMode entmode = tw.getFileMode(0); final RevObject ro = rw.lookupAny(entid, entmode.getObjectType()); rw.parseBody(ro); final ObjectLoader ldr = git.getRepository().open(ro.getId(), Constants.OBJ_BLOB); return ldr.openStream(); } } catch (final Throwable t) { throw new NoSuchFileException("Can't find '" + gitPath + "' in tree '" + treeRef + "'"); } finally { if (rw != null) { rw.dispose(); } if (tw != null) { tw.release(); } } throw new NoSuchFileException(""); }