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>
This commit is contained in:
parent
540df6c9fe
commit
8878d301ac
|
@ -323,6 +323,22 @@ public void copyTo(final OutputStream w) throws IOException {
|
||||||
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…
Reference in New Issue