Browse Source

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 <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 14 years ago
parent
commit
8878d301ac
  1. 16
      org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java

16
org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java

@ -323,6 +323,22 @@ public abstract class AnyObjectId implements Comparable {
w.write(toHexByteArray()); 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() { private byte[] toHexByteArray() {
final byte[] dst = new byte[Constants.OBJECT_ID_STRING_LENGTH]; final byte[] dst = new byte[Constants.OBJECT_ID_STRING_LENGTH];
formatHexByte(dst, 0, w1); formatHexByte(dst, 0, w1);

Loading…
Cancel
Save