From 8878d301ac6d79e2528be4a040a858c660e4cb30 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 29 Jul 2010 19:41:59 -0700 Subject: [PATCH] Add copyTo(byte[], int) to AnyObjectId This permits formatting in hex into an existing byte array supplied by the caller, and mirrors our copyRawTo method with the same parameter signature. Change-Id: Ia078d83e338b09b903bfd2d04284e5283f885a19 Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/lib/AnyObjectId.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java index c4c26a28e..e2060a0af 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java @@ -323,6 +323,22 @@ public abstract class AnyObjectId implements Comparable { w.write(toHexByteArray()); } + /** + * Copy this ObjectId to a byte array in hex format. + * + * @param b + * the buffer to copy to. + * @param o + * the offset within b to write at. + */ + public void copyTo(byte[] b, int o) { + formatHexByte(b, o + 0, w1); + formatHexByte(b, o + 8, w2); + formatHexByte(b, o + 16, w3); + formatHexByte(b, o + 24, w4); + formatHexByte(b, o + 32, w5); + } + private byte[] toHexByteArray() { final byte[] dst = new byte[Constants.OBJECT_ID_STRING_LENGTH]; formatHexByte(dst, 0, w1);