本文整理汇总了Java中org.eclipse.jgit.diff.RawText.isBinary方法的典型用法代码示例。如果您正苦于以下问题:Java RawText.isBinary方法的具体用法?Java RawText.isBinary怎么用?Java RawText.isBinary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.diff.RawText
的用法示例。
在下文中一共展示了RawText.isBinary方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import org.eclipse.jgit.diff.RawText; //导入方法依赖的package包/类
/**
* Format a patch script for one file entry.
*
* @param ent the entry to be formatted.
* @throws IOException a file's content cannot be read, or the output stream cannot
* be written to.
*/
public List<Hunk> format(DiffEntry ent) throws IOException {
//writeDiffHeader(out, ent);
if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
// writeGitLinkDiffText(out, ent);
return emptyList();
} else {
byte[] aRaw, bRaw;
try {
aRaw = open(objectReader, ent.getOldMode(), ent.getOldId());
bRaw = open(objectReader, ent.getNewMode(), ent.getNewId());
} finally {
// objectReader.release();
}
if (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
//out.write(encodeASCII("Binary files differ\n"));
return emptyList();
} else {
RawText a = new RawText(aRaw);
RawText b = new RawText(bRaw);
return formatEdits(a, b, MyersDiff.INSTANCE.diff(DEFAULT, a, b));
}
}
}
示例2: flatten
import org.eclipse.jgit.diff.RawText; //导入方法依赖的package包/类
public static FlatSource flatten(byte[] input) {
// file is binary, ignore all contents
if(RawText.isBinary(input)) return new FlatSource(new byte[0], new IntList());
IntList realLines = new IntList();
ByteBuffer to = ByteBuffer.allocate(input.length*2), from = ByteBuffer.wrap(input);
boolean atLineStart = true, lastWord = false, lastSpace = false;
while(from.hasRemaining()) {
if(atLineStart) {
realLines.add(to.position());
}
byte cur = from.get();
if (cur == '\n') {
atLineStart = true;
to.put(cur);
} else if (cur == ' ' || cur == '\t' ) {
if(!atLineStart && !lastSpace)
to.put((byte)'\n');
to.put(cur);
lastSpace = true;
lastWord = false;
atLineStart = false;
} else {
if(!atLineStart && !lastWord)
to.put((byte)'\n');
to.put(cur);
lastSpace = false;
lastWord = true;
atLineStart = false;
}
}
byte[] out = new byte[to.position()];
to.position(0);
to.get(out);
return new FlatSource(out, realLines);//new FlatSource(new byte[])
}
示例3: getFileContent
import org.eclipse.jgit.diff.RawText; //导入方法依赖的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;
}
示例4: onCreateLoader
import org.eclipse.jgit.diff.RawText; //导入方法依赖的package包/类
@Override
public Loader<BlobView> onCreateLoader(int id, Bundle b) {
return new AsyncLoader<BlobView>(getActivity()) {
public BlobView loadInBackground() {
Bundle args = getArguments();
try {
Repository repo = FileRepositoryBuilder.create(gitDirFrom(args));
ObjectId revision = repo.resolve(args.getString(UNTIL_REVS));
RevWalk revWalk = new RevWalk(repo);
RevCommit commit = revWalk.parseCommit(revision);
TreeWalk treeWalk = TreeWalk.forPath(repo, args.getString(PATH), commit.getTree());
ObjectId blobId = treeWalk.getObjectId(0);
ObjectLoader objectLoader = revWalk.getObjectReader().open(blobId, Constants.OBJ_BLOB);
ObjectStream binaryTestStream = objectLoader.openStream();
boolean blobIsBinary = RawText.isBinary(binaryTestStream);
binaryTestStream.close();
Log.d(TAG, "blobIsBinary="+blobIsBinary);
return blobIsBinary?new BinaryBlobView(objectLoader, treeWalk.getNameString()):new TextBlobView(objectLoader);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
示例5: getEditList
import org.eclipse.jgit.diff.RawText; //导入方法依赖的package包/类
private EditList getEditList(final DiffEntry entry)
throws LargeObjectException, MissingObjectException,
IncorrectObjectTypeException, IOException {
final ObjectId baseOid = entry.getNewId().toObjectId();
final byte[] currentObj = getBytesForObject(baseOid);
final ObjectId parentOid = entry.getOldId().toObjectId();
final byte[] parentObj = getBytesForObject(parentOid);
if (RawText.isBinary(currentObj) || RawText.isBinary(parentObj)) {
return new EditList();
}
return getDiff(currentObj, parentObj);
}
示例6: of
import org.eclipse.jgit.diff.RawText; //导入方法依赖的package包/类
private static EntryType of(org.eclipse.jgit.lib.Repository repo, TreeWalk walker, String entry) throws IOException {
if (entry.endsWith("/")) {
return EntryType.FOLDER;
}
ObjectId objectId = walker.getObjectId(0);
ObjectLoader loader = repo.open(objectId);
try (ObjectStream stream = loader.openStream()) {
if (RawText.isBinary(stream)) {
return EntryType.BINARY;
}
return EntryType.TEXT;
}
}
示例7: format
import org.eclipse.jgit.diff.RawText; //导入方法依赖的package包/类
public void format(final DiffEntry ent) throws IOException {
if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK
|| ent.getOldId() == null || ent.getNewId() == null) {
// No diff lines for git links, renames, file adds
return;
}
byte[] aRaw = open(OLD, ent);
byte[] bRaw = open(NEW, ent);
if (aRaw == BINARY || bRaw == BINARY //
|| RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
// No diff lines for binary files
return;
}
RawText a = new RawText(aRaw);
RawText b = new RawText(bRaw);
List<Edit> edits = diff(a, b);
for (int curIdx = 0; curIdx < edits.size();) {
Edit curEdit = edits.get(curIdx);
final int endIdx = findCombinedEnd(edits, curIdx);
final Edit endEdit = edits.get(endIdx);
int aCur = Math.max(0, curEdit.getBeginA() - context);
int bCur = Math.max(0, curEdit.getBeginB() - context);
final int aEnd = Math.min(a.size(), endEdit.getEndA() + context);
final int bEnd = Math.min(b.size(), endEdit.getEndB() + context);
final DiffContext diffContext = new DiffContext();
List<DiffLine> diffLines = Lists.newArrayListWithCapacity(2 * context + 1);
diffContext.setLines(diffLines);
while (aCur < aEnd || bCur < bEnd) {
DiffLine line = new DiffLine();
if (aCur < curEdit.getBeginA() || endIdx + 1 < curIdx) {
line.setContent(a.getString(aCur));
line.setNewLineNumber(bCur + 1);
line.setOldLineNumber(aCur + 1);
diffLines.add(line);
aCur++;
bCur++;
} else if (aCur < curEdit.getEndA()) {
line.setContent(a.getString(aCur));
line.setOldLineNumber(aCur + 1);
diffLines.add(line);
aCur++;
} else if (bCur < curEdit.getEndB()) {
line.setContent(b.getString(bCur));
line.setNewLineNumber(bCur + 1);
diffLines.add(line);
bCur++;
}
if (end(curEdit, aCur, bCur) && ++curIdx < edits.size())
curEdit = edits.get(curIdx);
}
list.add(diffContext);
}
}