本文整理汇总了Java中org.eclipse.jgit.lib.ObjectLoader.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectLoader.getSize方法的具体用法?Java ObjectLoader.getSize怎么用?Java ObjectLoader.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.lib.ObjectLoader
的用法示例。
在下文中一共展示了ObjectLoader.getSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: getSize
import org.eclipse.jgit.lib.ObjectLoader; //导入方法依赖的package包/类
@Override
public long getSize(@NotNull GitObject<? extends ObjectId> objectId) throws IOException {
final ObjectLoader loader = objectId.openObject();
final ObjectStream stream = loader.openStream();
final byte[] header = new byte[Constants.POINTER_MAX_SIZE];
int length = ByteStreams.read(stream, header, 0, header.length);
if (length < header.length) {
final Map<String, String> pointer = Pointer.parsePointer(header, 0, length);
if (pointer != null) {
return getReader(pointer).getSize();
}
}
return loader.getSize();
}
示例3: 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;
}
示例4: 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);
}