/** * Write instance {@code val} into buffer {@code buff}. */ public int encodeByte(byte[] buff, int offset, byte val) { return Bytes.putByte(buff, offset, val); } }
public static byte[] appendMetaData(byte[] id, byte[] data) { if (data == null || data.length == 0) { return data; } byte[] salt = Bytes.toBytes(ThreadLocalRandom.current().nextLong()); int idLength = id.length + salt.length; byte[] newData = new byte[MAGIC_SIZE + ID_LENGTH_SIZE + idLength + data.length]; int pos = 0; pos = Bytes.putByte(newData, pos, MAGIC); pos = Bytes.putInt(newData, pos, idLength); pos = Bytes.putBytes(newData, pos, id, 0, id.length); pos = Bytes.putBytes(newData, pos, salt, 0, salt.length); pos = Bytes.putBytes(newData, pos, data, 0, data.length); return newData; }
pos = Bytes.putShort(bytes, pos, (short)(rlength & 0x0000ffff)); pos = Bytes.putBytes(bytes, pos, row, roffset, rlength); pos = Bytes.putByte(bytes, pos, (byte)(flength & 0x0000ff)); if(flength != 0) { pos = Bytes.putBytes(bytes, pos, family, foffset, flength); pos = Bytes.putByte(bytes, pos, type.getCode()); if (vlength > 0) { if (value instanceof ByteBuffer) { int tlen = t.getValueLength(); pos = Bytes.putAsShort(bytes, pos, tlen + Tag.TYPE_LENGTH_SIZE); pos = Bytes.putByte(bytes, pos, t.getType()); Tag.copyValueTo(t, bytes, pos); pos += tlen;
/** * Format for a tag : * {@code <length of tag - 2 bytes><type code - 1 byte><tag>} tag length is serialized * using 2 bytes only but as this will be unsigned, we can have max tag length of * (Short.MAX_SIZE * 2) +1. It includes 1 byte type length and actual tag bytes length. */ public ArrayBackedTag(byte tagType, byte[] tag) { int tagLength = tag.length + TYPE_LENGTH_SIZE; if (tagLength > MAX_TAG_LENGTH) { throw new IllegalArgumentException( "Invalid tag data being passed. Its length can not exceed " + MAX_TAG_LENGTH); } length = TAG_LENGTH_SIZE + tagLength; bytes = new byte[length]; int pos = Bytes.putAsShort(bytes, 0, tagLength); pos = Bytes.putByte(bytes, pos, tagType); Bytes.putBytes(bytes, pos, tag, 0, tag.length); this.type = tagType; }
private static int encodeUnsignedByte(byte v, byte[] b, int o) { if (v < 0) { throw new RuntimeException(); } Bytes.putByte(b, o, v); return Bytes.SIZEOF_BYTE; }
pos = Bytes.putShort(bytes, pos, (short)(rlength & 0x0000ffff)); pos = Bytes.putBytes(bytes, pos, row, roffset, rlength); pos = Bytes.putByte(bytes, pos, (byte)(flength & 0x0000ff)); if(flength != 0) { pos = Bytes.putBytes(bytes, pos, family, foffset, flength); pos = Bytes.putByte(bytes, pos, type.getCode()); if (value != null && value.length > 0) { pos = Bytes.putBytes(bytes, pos, value, voffset, vlength);
@Override public int encode(PositionedByteRange dst, Byte val) { Bytes.putByte(dst.getBytes(), dst.getOffset() + dst.getPosition(), val); return skip(dst); }
pos = Bytes.putShort(buffer, pos, (short)(rlength & 0x0000ffff)); pos = Bytes.putBytes(buffer, pos, row, roffset, rlength); pos = Bytes.putByte(buffer, pos, (byte) (flength & 0x0000ff)); if (flength != 0) { pos = Bytes.putBytes(buffer, pos, family, foffset, flength); pos = Bytes.putByte(buffer, pos, type.getCode()); if (value != null && value.length > 0) { pos = Bytes.putBytes(buffer, pos, value, voffset, vlength); int tlen = t.getValueLength(); pos = Bytes.putAsShort(buffer, pos, tlen + Tag.TYPE_LENGTH_SIZE); pos = Bytes.putByte(buffer, pos, t.getType()); Tag.copyValueTo(t, buffer, pos); pos += tlen;
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; }
tlen = tag.getValueLength(); pos = Bytes.putAsShort(b, pos, tlen + Tag.TYPE_LENGTH_SIZE); pos = Bytes.putByte(b, pos, tag.getType()); if (tag.hasArray()) { pos = Bytes.putBytes(b, pos, tag.getValueArray(), tag.getValueOffset(), tlen);
Bytes.putByte(newKey, rightKey.length - TYPE_SIZE, Type.Maximum.getCode()); return newKey;
public static byte[] appendMetaData(byte[] id, byte[] data) { if (data == null || data.length == 0) { return data; } byte[] salt = Bytes.toBytes(ThreadLocalRandom.current().nextLong()); int idLength = id.length + salt.length; byte[] newData = new byte[MAGIC_SIZE + ID_LENGTH_SIZE + idLength + data.length]; int pos = 0; pos = Bytes.putByte(newData, pos, MAGIC); pos = Bytes.putInt(newData, pos, idLength); pos = Bytes.putBytes(newData, pos, id, 0, id.length); pos = Bytes.putBytes(newData, pos, salt, 0, salt.length); pos = Bytes.putBytes(newData, pos, data, 0, data.length); return newData; }
/** * 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); }
pos = Bytes.putByte(backingArray, pos, (byte)elemLen); IOUtils.readFully(cin, backingArray, pos, elemLen); pos += elemLen;
@Override public int encodeByte(byte v, byte[] b, int o) { if (v < 0) { throw newIllegalDataException(); } Bytes.putByte(b, o, v); return Bytes.SIZEOF_BYTE; } }
@Override public int encodeByte(byte v, byte[] b, int o) { if (v < 0) { throw new IllegalDataException(); } Bytes.putByte(b, o, v); return Bytes.SIZEOF_BYTE; } }
compression.getDictionary(CompressionContext.DictionaryIndex.FAMILY)); checkLength(elemLen, Byte.MAX_VALUE); pos = Bytes.putByte(backingArray, pos, (byte)elemLen); pos += elemLen;
private static void writeEndBytes(byte[] array, int newOffsetArrayPosition, int offsetArrayLength, int arrayLength, byte header, boolean useInt) { int byteSize = useInt ? Bytes.SIZEOF_INT : Bytes.SIZEOF_SHORT; Bytes.putInt(array, newOffsetArrayPosition + offsetArrayLength + byteSize, newOffsetArrayPosition); Bytes.putInt(array, newOffsetArrayPosition + offsetArrayLength + byteSize + Bytes.SIZEOF_INT, arrayLength); Bytes.putByte(array, newOffsetArrayPosition + offsetArrayLength + byteSize + 2 * Bytes.SIZEOF_INT, header); }
Bytes.putInt(newArray, currentPosition, useShortNew ? arrayLength : -arrayLength); currentPosition += Bytes.SIZEOF_INT; Bytes.putByte(newArray, currentPosition, arrayBytes[offset + length - 1]);