Search in sources :

Example 1 with UnionInputStream

use of org.eclipse.jgit.util.io.UnionInputStream in project gerrit by GerritCodeReview.

the class ReviewNoteMerger method merge.

@Override
public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException {
    if (ours == null) {
        return theirs;
    }
    if (theirs == null) {
        return ours;
    }
    if (ours.getData().equals(theirs.getData())) {
        return ours;
    }
    ObjectLoader lo = reader.open(ours.getData());
    byte[] sep = new byte[] { '\n' };
    ObjectLoader lt = reader.open(theirs.getData());
    try (ObjectStream os = lo.openStream();
        ByteArrayInputStream b = new ByteArrayInputStream(sep);
        ObjectStream ts = lt.openStream();
        UnionInputStream union = new UnionInputStream(os, b, ts)) {
        ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + sep.length + lt.getSize(), union);
        return new Note(ours, noteData);
    }
}
Also used : UnionInputStream(org.eclipse.jgit.util.io.UnionInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectId(org.eclipse.jgit.lib.ObjectId) ObjectStream(org.eclipse.jgit.lib.ObjectStream) Note(org.eclipse.jgit.notes.Note) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)1 ObjectStream (org.eclipse.jgit.lib.ObjectStream)1 Note (org.eclipse.jgit.notes.Note)1 UnionInputStream (org.eclipse.jgit.util.io.UnionInputStream)1