private static long readLong(byte[] raw, int offset) { long h = ((long) byteN(raw, offset)) << 56; h |= ((long) byteN(raw, offset + 1)) << 48; h |= ((long) byteN(raw, offset + 2)) << 40; h |= ((long) byteN(raw, offset + 3)) << 32; h |= ((long) byteN(raw, offset + 4)) << 24; h |= ((long) byteN(raw, offset + 5)) << 16; h |= ((long) byteN(raw, offset + 6)) << 8; h |= ((long) byteN(raw, offset + 7)) << 0; return h; }
/** * Copies the first {@code length} bytes of this objcetid's internal SHA-1 hash into * {@code target}, starting at {@code target}'s index zero. * * @pre {@code 0 <= length <= length} * @pre {@code target.length >= length} * @param target the byte array where to copy the specified number of bytes of this SHA-1 hash * sequence. * @param length how many bytes */ public void getRawValue(byte[] target, final int length) { Preconditions.checkArgument(length >= 0); Preconditions.checkArgument(length <= NUM_BYTES); Preconditions.checkArgument(target.length >= length); for (int i = 0; i < length; i++) { target[i] = (byte) byteN(i); } }
@Override public void funnel(ObjectId from, PrimitiveSink into) { for (int i = 0; i < ObjectId.NUM_BYTES; i++) { into.putByte((byte) from.byteN(i)); } } };
/** * Creates a hexadecimal encoding representation of the first {@code numBytes} bytes of the * SHA-1 hashcode represented by {@code id} and appends it to {@code target}. * * @pre {@code 0 < numBytes <= 20 } * @param id the {@code ObjectId} representing the SHA-1 hash to encode as an hex string * @param numBytes * @param target the {@code StringBuilder} where to append the string representation of the * {@link ObjectId} * @return {@code target} */ public static StringBuilder toString(final ObjectId id, final int numBytes, StringBuilder target) { Preconditions.checkNotNull(id); Preconditions.checkArgument(numBytes > 0 && numBytes <= ObjectId.NUM_BYTES); StringBuilder sb = target == null ? new StringBuilder(2 * numBytes) : target; int b; for (int i = 0; i < numBytes; i++) { b = id.byteN(i); sb.append(HEX_DIGITS[(b >> 4) & 0xf]).append(HEX_DIGITS[b & 0xf]); } return sb; }
/** * Creates a hexadecimal encoding representation of the first {@code numBytes} bytes of the * SHA-1 hashcode represented by {@code id} and appends it to {@code target}. * * @pre {@code 0 < numBytes <= 20 } * @param id the {@code ObjectId} representing the SHA-1 hash to encode as an hex string * @param numBytes * @param target the {@code StringBuilder} where to append the string representation of the * {@link ObjectId} * @return {@code target} */ public static StringBuilder toString(final ObjectId id, final int numBytes, StringBuilder target) { Preconditions.checkNotNull(id); Preconditions.checkArgument(numBytes > 0 && numBytes <= ObjectId.NUM_BYTES); StringBuilder sb = target == null ? new StringBuilder(2 * numBytes) : target; byte b; for (int i = 0; i < numBytes; i++) { b = (byte) id.byteN(i); sb.append(HEX_DIGITS[(b >> 4) & 0xf]).append(HEX_DIGITS[b & 0xf]); } return sb; }