Helper methods in ObjectId and AnyobjectId for int[], overload existing byte[] versions. Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx> --- .../src/org/spearce/jgit/lib/AnyObjectId.java | 16 ++++++++++++ .../src/org/spearce/jgit/lib/ObjectId.java | 26 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java index c348598..871a76d 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java @@ -276,6 +276,22 @@ public abstract class AnyObjectId implements Comparable { } /** + * Copy this ObjectId to an int array. + * + * @param b + * the buffer to copy to. + * @param o + * the offset within b to write at. + */ + public void copyRawTo(final int[] b, final int o) { + b[o] = w1; + b[o + 1] = w2; + b[o + 2] = w3; + b[o + 3] = w4; + b[o + 4] = w5; + } + + /** * Copy this ObjectId to an output writer in raw binary. * * @param w diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java index 9688a2e..7646a7b 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java @@ -168,6 +168,32 @@ public class ObjectId extends AnyObjectId { } /** + * Convert an ObjectId from raw binary representation. + * + * @param is + * the raw integers buffer to read from. At least 5 integers must + * be available within this int array. + * @return the converted object id. + */ + public static final ObjectId fromRaw(final int[] is) { + return fromRaw(is, 0); + } + + /** + * Convert an ObjectId from raw binary representation. + * + * @param is + * the raw integers buffer to read from. At least 5 integers + * after p must be available within this int array. + * @param p + * position to read the first integer of data from. + * @return the converted object id. + */ + public static final ObjectId fromRaw(final int[] is, final int p) { + return new ObjectId(is[p], is[p + 1], is[p + 2], is[p + 3], is[p + 4]); + } + + /** * Convert an ObjectId from hex characters (US-ASCII). * * @param buf -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html