/** * Write instance {@code val} into buffer {@code buff}. */ public int encodeLong(byte[] buff, int offset, long val) { return Bytes.putLong(buff, offset, val); } }
/** * @param bytes byte array * @param offset offset to write to * @param d value * @return New offset into array <code>bytes</code> */ public static int putDouble(byte [] bytes, int offset, double d) { return putLong(bytes, offset, Double.doubleToLongBits(d)); }
private static int encodeDouble(double v, byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_LONG); long l = Double.doubleToLongBits(v); l = (l ^ ((l >> Long.SIZE - 1) | Long.MIN_VALUE)) + 1; Bytes.putLong(b, o, l); return Bytes.SIZEOF_LONG; }
private static int encodeUnsignedLong(long v, byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_LONG); if (v < 0) { throw new RuntimeException(); } Bytes.putLong(b, o, v); return Bytes.SIZEOF_LONG; }
/** * @return a unique ID incorporating IP address, PID, TID and timer. Might be an overkill... * Note though that new UUID in java by default is just a random number. */ public static byte[] generateClientId() { byte[] selfBytes = getIpAddressBytes(); Long pid = getPid(); long tid = Thread.currentThread().getId(); long ts = System.currentTimeMillis(); byte[] id = new byte[selfBytes.length + ((pid != null ? 1 : 0) + 2) * Bytes.SIZEOF_LONG]; int offset = Bytes.putBytes(id, 0, selfBytes, 0, selfBytes.length); if (pid != null) { offset = Bytes.putLong(id, offset, pid); } offset = Bytes.putLong(id, offset, tid); offset = Bytes.putLong(id, offset, ts); assert offset == id.length; return id; }
@Override public int encode(PositionedByteRange dst, Long val) { Bytes.putLong(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
Bytes.putLong(newKey, rightKey.length - TIMESTAMP_TYPE_SIZE, HConstants.LATEST_TIMESTAMP); Bytes.putByte(newKey, rightKey.length - TYPE_SIZE, Type.Maximum.getCode()); return newKey;
pos = Bytes.putByte(bytes, pos, (byte)(flength & 0x0000ff)); pos += flength + qlength; pos = Bytes.putLong(bytes, pos, timestamp); pos = Bytes.putByte(bytes, pos, type.getCode()); pos += vlength;
@Test public void testCopyFromArrayToBuffer() { byte[] b = new byte[15]; b[0] = -1; long l = 988L; int i = 135; short s = 7; Bytes.putLong(b, 1, l); Bytes.putShort(b, 9, s); Bytes.putInt(b, 11, i); ByteBuffer buffer = ByteBuffer.allocate(14); ByteBufferUtils.copyFromArrayToBuffer(buffer, b, 1, 14); buffer.rewind(); assertEquals(l, buffer.getLong()); assertEquals(s, buffer.getShort()); assertEquals(i, buffer.getInt()); }
public static int appendKeyTo(final Cell cell, final byte[] output, final int offset) { int nextOffset = offset; nextOffset = Bytes.putShort(output, nextOffset, cell.getRowLength()); nextOffset = CellUtil.copyRowTo(cell, output, nextOffset); nextOffset = Bytes.putByte(output, nextOffset, cell.getFamilyLength()); nextOffset = CellUtil.copyFamilyTo(cell, output, nextOffset); nextOffset = CellUtil.copyQualifierTo(cell, output, nextOffset); nextOffset = Bytes.putLong(output, nextOffset, cell.getTimestamp()); nextOffset = Bytes.putByte(output, nextOffset, cell.getTypeByte()); return nextOffset; }
/** * Put the header into the given byte array at the given offset. * @param onDiskSize size of the block on disk header + data + checksum * @param uncompressedSize size of the block after decompression (but * before optional data block decoding) including header * @param onDiskDataSize size of the block on disk with header * and data but not including the checksums */ private void putHeader(byte[] dest, int offset, int onDiskSize, int uncompressedSize, int onDiskDataSize) { offset = blockType.put(dest, offset); offset = Bytes.putInt(dest, offset, onDiskSize - HConstants.HFILEBLOCK_HEADER_SIZE); offset = Bytes.putInt(dest, offset, uncompressedSize - HConstants.HFILEBLOCK_HEADER_SIZE); offset = Bytes.putLong(dest, offset, prevOffset); offset = Bytes.putByte(dest, offset, fileContext.getChecksumType().getCode()); offset = Bytes.putInt(dest, offset, fileContext.getBytesPerChecksum()); Bytes.putInt(dest, offset, onDiskDataSize); }
@Override public int encodeDouble(double v, byte[] b, int o) { long l = Double.doubleToLongBits(v); l = (l ^ ((l >> Long.SIZE - 1) | Long.MIN_VALUE)) + 1; Bytes.putLong(b, o, l); return Bytes.SIZEOF_LONG; }
@Override public int encodeDouble(double v, byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_LONG); long l = Double.doubleToLongBits(v); l = (l ^ ((l >> Long.SIZE - 1) | Long.MIN_VALUE)) + 1; Bytes.putLong(b, o, l); return Bytes.SIZEOF_LONG; }
@Override public int encodeLong(long v, byte[] b, int o) { if (v < 0) { throw new IllegalDataException(); } Bytes.putLong(b, o, v); return Bytes.SIZEOF_LONG; } }
pos = Bytes.putLong(bytes, pos, timestamp); pos = Bytes.putByte(bytes, pos, type.getCode()); if (vlength > 0) {
current.timestamp = current.timestamp - timestampOrDiff; Bytes.putLong(current.keyBuffer, pos, current.timestamp); pos += Bytes.SIZEOF_LONG;
pos = Bytes.putBytes(buffer, pos, qualifier, qoffset, qlength); pos = Bytes.putLong(buffer, pos, timestamp); pos = Bytes.putByte(buffer, pos, type.getCode()); if (value != null && value.length > 0) {
pos = Bytes.putBytes(bytes, pos, qualifier, qoffset, qlength); pos = Bytes.putLong(bytes, pos, timestamp); pos = Bytes.putByte(bytes, pos, type.getCode()); if (value != null && value.length > 0) {
@Override public int encodeLong(long v, byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_LONG); if (v < 0) { throw newIllegalDataException(); } Bytes.putLong(b, o, v); return Bytes.SIZEOF_LONG; } }