List of usage examples for org.eclipse.jgit.util RawParseUtils match
public static final int match(byte[] b, int ptr, byte[] src)
From source file:com.google.gerrit.server.notedb.ChangeRevisionNote.java
License:Apache License
private static String parsePushCert(Change.Id changeId, byte[] bytes, MutableInteger p) throws ConfigInvalidException { if (RawParseUtils.match(bytes, p.value, CERT_HEADER) < 0) { return null; }//from w w w.ja v a 2 s . co m int end = Bytes.indexOf(bytes, END_SIGNATURE); if (end < 0) { throw ChangeNotes.parseException(changeId, "invalid push certificate in note"); } int start = p.value; p.value = end + END_SIGNATURE.length; return new String(bytes, start, p.value, UTF_8); }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
public static List<PatchLineComment> parseNote(byte[] note, Change.Id changeId, Status status) throws ConfigInvalidException { List<PatchLineComment> result = Lists.newArrayList(); int sizeOfNote = note.length; Charset enc = RawParseUtils.parseEncoding(note); MutableInteger curr = new MutableInteger(); curr.value = 0;//from w ww . j a va 2 s.c o m boolean isForBase = (RawParseUtils.match(note, curr.value, PATCH_SET.getBytes(UTF_8))) < 0; PatchSet.Id psId = parsePsId(note, curr, changeId, enc, isForBase ? BASE_PATCH_SET : PATCH_SET); RevId revId = new RevId(parseStringField(note, curr, changeId, enc, REVISION)); PatchLineComment c = null; while (curr.value < sizeOfNote) { String previousFileName = c == null ? null : c.getKey().getParentKey().getFileName(); c = parseComment(note, curr, previousFileName, psId, revId, isForBase, enc, status); result.add(c); } return result; }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static PatchLineComment parseComment(byte[] note, MutableInteger curr, String currentFileName, PatchSet.Id psId, RevId revId, boolean isForBase, Charset enc, Status status) throws ConfigInvalidException { Change.Id changeId = psId.getParentKey(); // Check if there is a new file. boolean newFile = (RawParseUtils.match(note, curr.value, FILE.getBytes(UTF_8))) != -1; if (newFile) { // If so, parse the new file name. currentFileName = parseFilename(note, curr, changeId, enc); } else if (currentFileName == null) { throw parseException(changeId, "could not parse %s", FILE); }//from www. j av a2s.c o m CommentRange range = parseCommentRange(note, curr); if (range == null) { throw parseException(changeId, "could not parse %s", COMMENT_RANGE); } Timestamp commentTime = parseTimestamp(note, curr, changeId, enc); Account.Id aId = parseAuthor(note, curr, changeId, enc); boolean hasParent = (RawParseUtils.match(note, curr.value, PARENT.getBytes(enc))) != -1; String parentUUID = null; if (hasParent) { parentUUID = parseStringField(note, curr, changeId, enc, PARENT); } String uuid = parseStringField(note, curr, changeId, enc, UUID); int commentLength = parseCommentLength(note, curr, changeId, enc); String message = RawParseUtils.decode(enc, note, curr.value, curr.value + commentLength); checkResult(message, "message contents", changeId); PatchLineComment plc = new PatchLineComment( new PatchLineComment.Key(new Patch.Key(psId, currentFileName), uuid), range.getEndLine(), aId, parentUUID, commentTime); plc.setMessage(message); plc.setSide((short) (isForBase ? 0 : 1)); if (range.getStartCharacter() != -1) { plc.setRange(range); } plc.setRevId(revId); plc.setStatus(status); curr.value = RawParseUtils.nextLF(note, curr.value + commentLength); curr.value = RawParseUtils.nextLF(note, curr.value); return plc; }
From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java
License:Apache License
private static void checkHeaderLineFormat(byte[] note, MutableInteger curr, String fieldName, Charset enc, Change.Id changeId) throws ConfigInvalidException { boolean correct = RawParseUtils.match(note, curr.value, fieldName.getBytes(enc)) != -1; correct &= (note[curr.value + fieldName.length()] == ':'); correct &= (note[curr.value + fieldName.length() + 1] == ' '); if (!correct) { throw parseException(changeId, "could not parse %s", fieldName); }//from ww w .j a v a 2 s . com }
From source file:com.google.gerrit.server.notedb.RevisionNote.java
License:Apache License
private static String parsePushCert(Change.Id changeId, byte[] bytes, MutableInteger p) throws ConfigInvalidException { if (RawParseUtils.match(bytes, p.value, CERT_HEADER) < 0) { return null; }//from w w w . j av a 2 s. c o m int end = Bytes.indexOf(bytes, END_SIGNATURE); if (end < 0) { throw ChangeNotes.parseException(changeId, "invalid push certificate in note"); } int start = p.value; p.value = end + END_SIGNATURE.length; return new String(bytes, start, p.value); }