当前位置: 首页>>代码示例>>Java>>正文


Java ObjectLoader.getCachedBytes方法代码示例

本文整理汇总了Java中org.eclipse.jgit.lib.ObjectLoader.getCachedBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectLoader.getCachedBytes方法的具体用法?Java ObjectLoader.getCachedBytes怎么用?Java ObjectLoader.getCachedBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jgit.lib.ObjectLoader的用法示例。


在下文中一共展示了ObjectLoader.getCachedBytes方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: open

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private byte[] open(ObjectReader reader, FileMode mode,
                    AbbreviatedObjectId id) throws IOException {
    if (mode == FileMode.MISSING)
        return new byte[] { };

    if (mode.getObjectType() != Constants.OBJ_BLOB)
        return new byte[] { };

    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1)
            id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
        else if (ids.size() == 0)
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        else
            throw new AmbiguousObjectException(id, ids);
    }

    ObjectLoader ldr = reader.open(id.toObjectId());
    return ldr.getCachedBytes(bigFileThreshold);
}
 
开发者ID:m4rzEE1,项目名称:ninja_chic-,代码行数:22,代码来源:LineContextDiffer.java

示例2: getByteContent

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
/**
 * Retrieves the raw byte content of a file in the specified tree.
 * 
 * @param repository
 * @param tree
 *            if null, the RevTree from HEAD is assumed.
 * @param path
 * @return content as a byte []
 */
public static byte[] getByteContent(Repository repository, RevTree tree, final String path, boolean throwError) {
	RevWalk rw = new RevWalk(repository);
	byte[] content = null;
	try (TreeWalk tw = new TreeWalk(repository)) {
		tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
		if (tree == null) {
			ObjectId object = getDefaultBranch(repository);
			if (object == null) {
				return null;
			}
			RevCommit commit = rw.parseCommit(object);
			tree = commit.getTree();
		}
		tw.reset(tree);
		while (tw.next()) {
			if (tw.isSubtree() && !path.equals(tw.getPathString())) {
				tw.enterSubtree();
				continue;
			}
			ObjectId entid = tw.getObjectId(0);
			FileMode entmode = tw.getFileMode(0);
			if (entmode != FileMode.GITLINK) {
				ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
				content = ldr.getCachedBytes();
			}
		}
	} catch (Throwable t) {
		if (throwError) {
			error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name());
		}
	} finally {
		rw.close();
		rw.dispose();
	}
	return content;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:46,代码来源:JGitUtils.java

示例3: getCachedBytes

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
byte[] getCachedBytes(RevObject obj, ObjectLoader ldr)
		throws LargeObjectException, MissingObjectException, IOException {
	try {
		return ldr.getCachedBytes(5 * MB);
	} catch (LargeObjectException tooBig) {
		tooBig.setObjectId(obj);
		throw tooBig;
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:10,代码来源:RevWalk.java

示例4: makePack

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
/**
 * Function used to treat pack object, it load the data from each object of
 * the pack to create the original object when the object is recreate it
 * store the object into the git object index
 *
 * @author Sylvain
 *
 * @param pathPack
 *            the path of the pack file
 * @throws IOException
 * @throws DataFormatException
 */
public static void makePack(String pathPack) throws IOException, DataFormatException {
	String[] path = pathPack.split(osBarre + ".git" + osBarre);
	RepositoryBuilder builder = new RepositoryBuilder();
	builder.setMustExist(true);
	builder.setGitDir(new File(path[0] + osBarre + ".git" + osBarre));
	Repository repository = builder.build();

	for (MutableEntry mutableEntry : new PackFile(new File(pathPack), 0)) {
		GitObject obj = null;
		String sha1 = mutableEntry.toObjectId().name();
		ObjectId id = repository.resolve(sha1);
		ObjectLoader loader = repository.open(id);

		switch (loader.getType()) {
		case Constants.OBJ_BLOB:
			obj = new GitBlob(loader.getSize(), sha1, "", loader.getCachedBytes());
			break;
		case Constants.OBJ_COMMIT:
			obj = new GitCommit(loader.getSize(), sha1, new String(loader.getCachedBytes()));
			break;
		case Constants.OBJ_TREE:
			obj = new GitTree(loader.getSize(), sha1, loader.getBytes());
			break;
		case Constants.OBJ_TAG:
			obj = new GitTag(loader.getSize(), sha1, new String(loader.getCachedBytes()));
			break;
		default:
			break;
		}

		GitObjectsIndex.getInstance().put(mutableEntry.toObjectId().name(), obj);
	}
}
 
开发者ID:VieVie31,项目名称:gitant,代码行数:46,代码来源:MainWindow.java

示例5: readFile

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
protected byte[] readFile(String fileName) throws IOException {
  if (revision == null) {
    return new byte[] {};
  }

  TreeWalk tw = TreeWalk.forPath(reader, fileName, revision.getTree());
  if (tw != null) {
    ObjectLoader obj = reader.open(tw.getObjectId(0), Constants.OBJ_BLOB);
    return obj.getCachedBytes(Integer.MAX_VALUE);
  }
  return new byte[] {};
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:13,代码来源:VersionedMetaData.java

示例6: getContent

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public BinaryResult getContent(
    Repository repo, ProjectState project, ObjectId revstr, String path)
    throws IOException, ResourceNotFoundException {
  try (RevWalk rw = new RevWalk(repo)) {
    RevCommit commit = rw.parseCommit(revstr);
    ObjectReader reader = rw.getObjectReader();
    TreeWalk tw = TreeWalk.forPath(reader, path, commit.getTree());
    if (tw == null) {
      throw new ResourceNotFoundException();
    }

    org.eclipse.jgit.lib.FileMode mode = tw.getFileMode(0);
    ObjectId id = tw.getObjectId(0);
    if (mode == org.eclipse.jgit.lib.FileMode.GITLINK) {
      return BinaryResult.create(id.name()).setContentType(X_GIT_GITLINK).base64();
    }

    ObjectLoader obj = repo.open(id, OBJ_BLOB);
    byte[] raw;
    try {
      raw = obj.getCachedBytes(MAX_SIZE);
    } catch (LargeObjectException e) {
      raw = null;
    }

    String type;
    if (mode == org.eclipse.jgit.lib.FileMode.SYMLINK) {
      type = X_GIT_SYMLINK;
    } else {
      type = registry.getMimeType(path, raw).toString();
      type = resolveContentType(project, path, FileMode.FILE, type);
    }

    return asBinaryResult(raw, obj).setContentType(type).base64();
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:37,代码来源:FileContentUtil.java

示例7: readProjectConfig

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private Config readProjectConfig() throws Exception {
  RevWalk rw = testRepo.getRevWalk();
  RevTree tree = rw.parseTree(testRepo.getRepository().resolve("HEAD"));
  RevObject obj = rw.parseAny(testRepo.get(tree, "project.config"));
  ObjectLoader loader = rw.getObjectReader().open(obj);
  String text = new String(loader.getCachedBytes(), UTF_8);
  Config cfg = new Config();
  cfg.fromText(text);
  return cfg;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:11,代码来源:ConfigChangeIT.java

示例8: TextBlobView

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
TextBlobView(ObjectLoader objectLoader) throws IOException {
    byte[] cachedBytes = objectLoader.getCachedBytes();
    Log.d(TAG, "Got " + cachedBytes.length + " of data");

    String decode = RawParseUtils.decode(cachedBytes);

    blobHTML = dressFileContentForWebView(decode);
}
 
开发者ID:m4rzEE1,项目名称:ninja_chic-,代码行数:9,代码来源:BlobViewFragment.java

示例9: getBaseConfig

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
@Nullable
private static Config getBaseConfig(@NotNull Repository repository, @NotNull String configFileName) throws IOException, ConfigInvalidException {
	final Config baseConfig;
	if (repository.isBare()) {
		// read bugtraq config directly from the repository
		String content = null;
		RevWalk rw = new RevWalk(repository);
		try (TreeWalk tw = new TreeWalk(repository)) {
			tw.setFilter(PathFilterGroup.createFromStrings(configFileName));
			Ref head = repository.getRef(Constants.HEAD);
			if (head == null) {
				return null;
			}
			head = head.getTarget();
			if (head == null) {
				return null;
			}
			ObjectId headId = head.getObjectId();
			if (headId == null) {
				return null;
			}
			RevCommit commit = rw.parseCommit(headId);
			RevTree tree = commit.getTree();
			tw.reset(tree);
			while (tw.next()) {
				ObjectId entid = tw.getObjectId(0);
				FileMode entmode = tw.getFileMode(0);
				if (FileMode.REGULAR_FILE == entmode) {
					ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
					content = new String(ldr.getCachedBytes(), commit.getEncoding());
					break;
				}
			}
		} finally {
			rw.close();
			rw.dispose();
		}

		if (content == null) {
			// config not found
			baseConfig = null;
		} else {
			// parse the config
			Config config = new Config();
			config.fromText(content);
			baseConfig = config;
		}
	} else {
		// read bugtraq config from work tree
		final File baseFile = new File(repository.getWorkTree(), configFileName);
		if (baseFile.isFile()) {
			FileBasedConfig fileConfig = new FileBasedConfig(baseFile, repository.getFS());
			fileConfig.load();
			baseConfig = fileConfig;
		} else {
			baseConfig = null;
		}
	}
	return baseConfig;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:61,代码来源:BugtraqConfig.java

示例10: indexBlob

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
private void indexBlob(IndexWriter writer, Repository repository, 
		SymbolExtractor<Symbol> extractor, ObjectId blobId, String blobPath) throws IOException {
	Document document = new Document();
	
	document.add(new StoredField(BLOB_INDEX_VERSION.name(), getCurrentBlobIndexVersion(extractor)));
	document.add(new StringField(BLOB_HASH.name(), blobId.name(), Store.NO));
	document.add(new StringField(BLOB_PATH.name(), blobPath, Store.YES));
	
	String blobName = blobPath;
	if (blobPath.indexOf('/') != -1) 
		blobName = StringUtils.substringAfterLast(blobPath, "/");
	
	document.add(new StringField(BLOB_NAME.name(), blobName.toLowerCase(), Store.NO));
	
	ObjectLoader objectLoader = repository.open(blobId);
	if (objectLoader.getSize() <= MAX_INDEXABLE_SIZE) {
		byte[] bytes = objectLoader.getCachedBytes();
		String content = ContentDetector.convertToText(bytes, blobName);
		if (content != null) {
			document.add(new TextField(BLOB_TEXT.name(), content, Store.NO));
			
			if (extractor != null) {
				try {
					List<Symbol> symbols = extractor.extract(blobName, content);
					for (Symbol symbol: symbols) {
						String fieldValue = symbol.getName();
						if (fieldValue != null && symbol.isSearchable()) {
							fieldValue = fieldValue.toLowerCase();

							String fieldName;
							if (symbol.isPrimary())
								fieldName = BLOB_PRIMARY_SYMBOLS.name();
							else
								fieldName = BLOB_SECONDARY_SYMBOLS.name();
							document.add(new StringField(fieldName, fieldValue, Store.NO));
						}
					}
					byte[] bytesOfSymbols = SerializationUtils.serialize((Serializable) symbols);
					document.add(new StoredField(BLOB_SYMBOL_LIST.name(), bytesOfSymbols));
				} catch (ExtractException e) {
					logger.debug("Error extracting symbols from blob (hash:" + blobId.name() + ", path:" + blobPath + ")", e);
				}
			} 
		} else {
			logger.debug("Ignore content of binary file '{}'.", blobPath);
		}
	} else {
		logger.debug("Ignore content of large file '{}'.", blobPath);
	}

	writer.addDocument(document);
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:53,代码来源:DefaultIndexManager.java

示例11: asByteArray

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public static byte[] asByteArray(ObjectLoader ldr)
    throws MissingObjectException, LargeObjectException, IOException {
  return ldr.getCachedBytes(bigFileThreshold);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:5,代码来源:Text.java

示例12: downloadContent

import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
public BinaryResult downloadContent(
    ProjectState project, ObjectId revstr, String path, @Nullable Integer parent)
    throws ResourceNotFoundException, IOException {
  try (Repository repo = openRepository(project);
      RevWalk rw = new RevWalk(repo)) {
    String suffix = "new";
    RevCommit commit = rw.parseCommit(revstr);
    if (parent != null && parent > 0) {
      if (commit.getParentCount() == 1) {
        suffix = "old";
      } else {
        suffix = "old" + parent;
      }
      commit = rw.parseCommit(commit.getParent(parent - 1));
    }
    ObjectReader reader = rw.getObjectReader();
    TreeWalk tw = TreeWalk.forPath(reader, path, commit.getTree());
    if (tw == null) {
      throw new ResourceNotFoundException();
    }

    int mode = tw.getFileMode(0).getObjectType();
    if (mode != Constants.OBJ_BLOB) {
      throw new ResourceNotFoundException();
    }

    ObjectId id = tw.getObjectId(0);
    ObjectLoader obj = repo.open(id, OBJ_BLOB);
    byte[] raw;
    try {
      raw = obj.getCachedBytes(MAX_SIZE);
    } catch (LargeObjectException e) {
      raw = null;
    }

    MimeType contentType = registry.getMimeType(path, raw);
    return registry.isSafeInline(contentType)
        ? wrapBlob(path, obj, raw, contentType, suffix)
        : zipBlob(path, obj, commit, suffix);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:42,代码来源:FileContentUtil.java


注:本文中的org.eclipse.jgit.lib.ObjectLoader.getCachedBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。