本文整理汇总了Java中org.eclipse.jgit.lib.ObjectLoader.copyTo方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectLoader.copyTo方法的具体用法?Java ObjectLoader.copyTo怎么用?Java ObjectLoader.copyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.lib.ObjectLoader
的用法示例。
在下文中一共展示了ObjectLoader.copyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFromCommit
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public byte[] readFromCommit(String commitId, String path) throws Exception {
try (RevWalk revWalk = new RevWalk(localRepo)) {
RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
// use commit's tree find the path
RevTree tree = commit.getTree();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(path));
if (!treeWalk.next()) {
return null;
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = localRepo.open(objectId);
loader.copyTo(baos);
}
revWalk.dispose();
return baos.toByteArray();
}
}
示例2: getFileFromCommit
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public static boolean getFileFromCommit(final OutputStream os, final String file, final Repository repo, final RevTree tree) throws IOException, GitAPIException {
final TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(file));
if (!treeWalk.next()) {
logger.info("Did not find expected file '" + file + "'");
return false;
}
final ObjectId objectId = treeWalk.getObjectId(0);
final ObjectLoader loader = repo.open(objectId);
// and then one can the loader to read the file
loader.copyTo(os);
return true;
}
示例3: main
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// a RevWalk allows to retrieve information from the repository
try (RevWalk walk = new RevWalk(repository)) {
// a simple tag that is not annotated
Ref simpleTag = repository.findRef("initialtag");
RevObject any = walk.parseAny(simpleTag.getObjectId());
System.out.println("Commit: " + any);
// an annotated tag
Ref annotatedTag = repository.findRef("secondtag");
any = walk.parseAny(annotatedTag.getObjectId());
System.out.println("Tag: " + any);
// finally try to print out the tag-content
System.out.println("\nTag-Content: \n");
ObjectLoader loader = repository.open(annotatedTag.getObjectId());
loader.copyTo(System.out);
walk.dispose();
}
}
}
示例4: main
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// the Ref holds an ObjectId for any type of object (tree, commit, blob, tree)
Ref head = repository.exactRef("refs/heads/master");
System.out.println("Ref of refs/heads/master: " + head);
System.out.println("\nPrint contents of head of master branch, i.e. the latest commit information");
ObjectLoader loader = repository.open(head.getObjectId());
loader.copyTo(System.out);
System.out.println("\nPrint contents of tree of head of master branch, i.e. the latest binary tree information");
// a commit points to a tree
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(head.getObjectId());
RevTree tree = walk.parseTree(commit.getTree().getId());
System.out.println("Found Tree: " + tree);
loader = repository.open(tree.getId());
loader.copyTo(System.out);
walk.dispose();
}
}
}
示例5: getLastRevision
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public static void getLastRevision(Git git, String base, String name,
String rev, OutputStream out, String ext)
throws WsSrvException, IOException {
checkFile(base, name, ext);
String fp = getLocalPath(name);
// find the HEAD
ObjectId lastCommitId = git.getRepository().resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on
// some filtering that is defined
RevWalk revWalk = new RevWalk(git.getRepository());
RevCommit commit = revWalk.parseCommit(lastCommitId);
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now try to find a specific file
TreeWalk treeWalk = new TreeWalk(git.getRepository());
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(fp));
if (!treeWalk.next()) {
throw new IllegalStateException(
"Did not find expected file 'README.md'");
}
ObjectId objectId = treeWalk.getObjectId(0);
System.out.println("ObjectId: " + objectId.toString());
ObjectLoader loader = git.getRepository().open(objectId);
// and then one can the loader to read the file
loader.copyTo(System.out);
revWalk.dispose();
}
示例6: noteToString
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
/**
* Utility method that converts a note to a string (assuming it's UTF-8).
*/
private String noteToString(Repository repo, Note note)
throws MissingObjectException, IOException, UnsupportedEncodingException {
ObjectLoader loader = repo.open(note.getData());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
loader.copyTo(baos);
return new String(baos.toByteArray(), "UTF-8");
}
示例7: asBinaryResult
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private static BinaryResult asBinaryResult(byte[] raw, ObjectLoader obj) {
if (raw != null) {
return BinaryResult.create(raw);
}
BinaryResult result =
new BinaryResult() {
@Override
public void writeTo(OutputStream os) throws IOException {
obj.copyTo(os);
}
};
result.setContentLength(obj.getSize());
return result;
}
示例8: getLines
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private List<String> getLines(final ObjectId id,
final int fromStart,
final int fromEnd) throws IOException {
List<String> lines = new ArrayList<>();
if (!id.equals(ObjectId.zeroId())) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
final ObjectLoader loader = git.getRepository().open(id);
loader.copyTo(stream);
final String content = stream.toString();
final List<String> filteredLines = Arrays.asList(content.split("\n"));
lines = filteredLines.subList(fromStart,
fromEnd);
}
return lines;
}
示例9: getFileContent
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private FileContent getFileContent(Git git, String path, ObjectId objectId) {
try {
ObjectLoader loader = git.getRepository().open(objectId);
if (RawText.isBinary(loader.openStream())) {
return new FileContent(path, true, null);
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
loader.copyTo(stream);
return new FileContent(path, false, stream.toString());
} catch (IOException e) {
}
return null;
}
示例10: streamFromRepo
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
protected boolean streamFromRepo(HttpServletRequest request, HttpServletResponse response, Repository repository, RevCommit commit,
String requestedPath) throws IOException {
boolean served = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
PathFilter f = PathFilter.create(requestedPath);
tw.setFilter(f);
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
while (tw.next()) {
FileMode mode = tw.getFileMode(0);
if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
continue;
}
tw.getObjectId(id, 0);
String filename = StringUtils.getLastPathElement(requestedPath);
try {
String userAgent = request.getHeader("User-Agent");
if (userAgent != null && userAgent.indexOf("MSIE 5.5") > -1) {
response.setHeader("Content-Disposition", "filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
} else if (userAgent != null && userAgent.indexOf("MSIE") > -1) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
} else {
response.setHeader("Content-Disposition", "attachment; filename=\""
+ new String(filename.getBytes(Constants.ENCODING), "latin1") + "\"");
}
} catch (UnsupportedEncodingException e) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
}
long len = reader.getObjectSize(id, org.eclipse.jgit.lib.Constants.OBJ_BLOB);
setContentType(response, "application/octet-stream");
response.setIntHeader("Content-Length", (int) len);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(response.getOutputStream());
served = true;
}
} finally {
tw.close();
rw.dispose();
}
response.flushBuffer();
return served;
}
示例11: zip
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
/**
* Zips the contents of the tree at the (optionally) specified revision and the (optionally) specified basepath to the supplied outputstream.
*
* @param repository
* @param basePath
* if unspecified, entire repository is assumed.
* @param objectId
* if unspecified, HEAD is assumed.
* @param os
* @return true if repository was successfully zipped to supplied output stream
*/
public static boolean zip(Repository repository, String basePath, String objectId, OutputStream os) {
RevCommit commit = JGitUtils.getCommit(repository, objectId);
if (commit == null) {
return false;
}
boolean success = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setComment("Generated by Gitblit");
if (!StringUtils.isEmpty(basePath)) {
PathFilter f = PathFilter.create(basePath);
tw.setFilter(f);
}
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
long modified = commit.getAuthorIdent().getWhen().getTime();
while (tw.next()) {
FileMode mode = tw.getFileMode(0);
if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
continue;
}
tw.getObjectId(id, 0);
ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
entry.setComment(commit.getName());
entry.setUnixMode(mode.getBits());
entry.setTime(modified);
zos.putArchiveEntry(entry);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(zos);
zos.closeArchiveEntry();
}
zos.finish();
success = true;
} catch (IOException e) {
error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
} finally {
tw.close();
rw.close();
rw.dispose();
}
return success;
}
示例12: walkGitObjectTree
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private Map<String, RawFile> walkGitObjectTree(Optional<Long> maxFileSize)
throws IOException,
SizeLimitExceededException,
InvalidGitRepository {
Map<String, RawFile> fileContentsTable = new HashMap<>();
if (treeWalk == null) {
return fileContentsTable;
}
while (treeWalk.next()) {
String path = treeWalk.getPathString();
ObjectId objectId = treeWalk.getObjectId(0);
if (!repository.hasObject(objectId)) {
throw new InvalidGitRepository();
}
ObjectLoader obj = repository.open(objectId);
long size = obj.getSize();
if (maxFileSize.isPresent() && size > maxFileSize.get()) {
throw new SizeLimitExceededException(
Optional.ofNullable(path), size, maxFileSize.get());
}
try (ByteArrayOutputStream o = new ByteArrayOutputStream(
CastUtil.assumeInt(size))) {
obj.copyTo(o);
fileContentsTable.put(
path, new RepositoryFile(path, o.toByteArray()));
};
}
return fileContentsTable;
}
示例13: zip
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
/**
* Zips the contents of the tree at the (optionally) specified revision and
* the (optionally) specified basepath to the supplied outputstream.
*
* @param repository
* @param basePath
* if unspecified, entire repository is assumed.
* @param objectId
* if unspecified, HEAD is assumed.
* @param os
* @return true if repository was successfully zipped to supplied output
* stream
*/
public static boolean zip(Repository repository, String basePath, String objectId,
OutputStream os) {
RevCommit commit = JGitUtils.getCommit(repository, objectId);
if (commit == null) {
return false;
}
boolean success = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setComment("Generated by Gitblit");
if (!StringUtils.isEmpty(basePath)) {
PathFilter f = PathFilter.create(basePath);
tw.setFilter(f);
}
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
long modified = commit.getAuthorIdent().getWhen().getTime();
while (tw.next()) {
FileMode mode = tw.getFileMode(0);
if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
continue;
}
tw.getObjectId(id, 0);
ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
entry.setComment(commit.getName());
entry.setUnixMode(mode.getBits());
entry.setTime(modified);
zos.putArchiveEntry(entry);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(zos);
zos.closeArchiveEntry();
}
zos.finish();
success = true;
} catch (IOException e) {
error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
} finally {
tw.release();
rw.dispose();
}
return success;
}
示例14: main
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// find the HEAD
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk revWalk = new RevWalk(repository)) {
RevCommit commit = revWalk.parseCommit(lastCommitId);
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now try to find a specific file
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create("README.md"));
if (!treeWalk.next()) {
throw new IllegalStateException("Did not find expected file 'README.md'");
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
// and then one can the loader to read the file
loader.copyTo(System.out);
}
revWalk.dispose();
}
}
}
示例15: countLinesOfFileInCommit
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private static int countLinesOfFileInCommit(Repository repository, ObjectId commitID, String name) throws IOException {
try (RevWalk revWalk = new RevWalk(repository)) {
RevCommit commit = revWalk.parseCommit(commitID);
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
// now try to find a specific file
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(name));
if (!treeWalk.next()) {
throw new IllegalStateException("Did not find expected file 'README.md'");
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
// load the content of the file into a stream
ByteArrayOutputStream stream = new ByteArrayOutputStream();
loader.copyTo(stream);
revWalk.dispose();
return IOUtils.readLines(new ByteArrayInputStream(stream.toByteArray()), "UTF-8").size();
}
}
}