@Override public ByteArray deserialize(ByteBuffer in) { //the array in ByteArray is garanteed to be completed owned by the ByteArray return new ByteArray(BytesUtil.readByteArray(in)); } }
private void serializeGTRecord(GTRecord gtRecord, ByteBuffer out) { BytesUtil.writeVInt(gtRecord.cols.length, out); for (ByteArray col : gtRecord.cols) { col.exportData(out); } }
@Override public Object deserialize(ByteBuffer in) { int id = BytesUtil.readUnsigned(in, dict.getSizeOfId()); return dict.getValueFromId(id); }
@Override public void serialize(ByteArray code, ByteBuffer buffer) { if (code == null) BytesUtil.writeByteArray(null, 0, 0, buffer); else BytesUtil.writeByteArray(code.array(), code.offset(), code.length(), buffer); }
public static void writeUTFString(String str, ByteBuffer out) { byte[] bytes = str == null ? null : Bytes.toBytes(str); writeByteArray(bytes, out); }
public static String readUTFString(ByteBuffer in) { byte[] bytes = readByteArray(in); return bytes == null ? null : Bytes.toString(bytes); }
public int sizeOf(ImmutableBitSet selectedCols) { int size = 0; for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); size += cols[c].length(); } return size; }
@Override public int hashCode() { if (data == null) { return 0; } else { if (length <= Bytes.SIZEOF_LONG && length > 0) { // to avoid hash collision of byte arrays those are converted from nearby integers/longs, which is the case for kylin dictionary long value = BytesUtil.readLong(data, offset, length); return (int) (value ^ (value >>> 32)); } return Bytes.hashCode(data, offset, length); } }
@Override public int hashCode() { int hash = 1; for (int i = 0; i < info.colAll.trueBitCount(); i++) { int c = info.colAll.trueBitAt(i); hash = (31 * hash) + cols[c].hashCode(); } return hash; }
public String toReadableText() { if (data == null) { return null; } else { return BytesUtil.toHex(data, offset, length); } }
@Override public void createTestMetadata(String... overlayMetadataDirs) { staticCreateTestMetadata(true, new OverlayMetaHook(overlayMetadataDirs)); }
/** reserve without wait, fail with NotEnoughBudgetException immediately if no mem */ public void reserve(MemoryConsumer consumer, int requestMB) { if (totalBudgetMB == 0 && requestMB > 0) throw new NotEnoughBudgetException(); boolean ok = false; while (!ok) { int gap = calculateGap(consumer, requestMB); if (gap > 0) { // to void deadlock, don't hold lock when invoking consumer.freeUp() tryFreeUp(gap); } ok = updateBooking(consumer, requestMB); } }
/** * @param b bytes to hash * @return Runs {@link org.apache.hadoop.io.WritableComparator#hashBytes(byte[], int)} on the * passed in array. This method is what {@link org.apache.hadoop.io.Text} and * {@link org.apache.hadoop.hbase.io.ImmutableBytesWritable} use calculating hash code. */ public static int hashCode(final byte[] b) { return hashCode(b, b.length); }
/** * @param a array * @param length new array size * @return Value in <code>a</code> plus <code>length</code> prepended 0 bytes */ public static byte[] padHead(final byte[] a, final int length) { byte[] padding = new byte[length]; for (int i = 0; i < length; i++) { padding[i] = 0; } return add(padding, a); }
@Override public void serialize(ByteArray value, ByteBuffer out) { if (value != null && value.array() != null) { BytesUtil.writeByteArray(value.array(), value.offset(), value.length(), out); } else { BytesUtil.writeByteArray(null, out); } }
@Override public ByteArray deserialize(ByteBuffer buffer) { return new ByteArray(BytesUtil.readByteArray(buffer)); } };
/** * @param a array * @param length new array size * @return Value in <code>a</code> plus <code>length</code> appended 0 bytes */ public static byte[] padTail(final byte[] a, final int length) { byte[] padding = new byte[length]; for (int i = 0; i < length; i++) { padding[i] = 0; } return add(a, padding); }
public static ByteArray importData(ByteBuffer in) { byte[] bytes = BytesUtil.readByteArray(in); return new ByteArray(bytes); }