public static void appendToByteBuffer(final ByteBuffer bb, final KeyValue kv, final boolean includeMvccVersion) { // keep pushing the limit out. assume enough capacity bb.limit(bb.position() + kv.getLength()); bb.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includeMvccVersion) { int numMvccVersionBytes = WritableUtils.getVIntSize(kv.getSequenceId()); ByteBufferUtils.extendLimit(bb, numMvccVersionBytes); ByteBufferUtils.writeVLong(bb, kv.getSequenceId()); } }
@Test public void testReadWriteVLong() { for (long l : testNumbers) { ByteBuffer b = ByteBuffer.allocate(MAX_VLONG_LENGTH); ByteBufferUtils.writeVLong(b, l); b.flip(); assertEquals(l, ByteBufferUtils.readVLong(b)); } }
@Test public void testConsistencyWithHadoopVLong() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (long l : testNumbers) { baos.reset(); ByteBuffer b = ByteBuffer.allocate(MAX_VLONG_LENGTH); ByteBufferUtils.writeVLong(b, l); String bufStr = Bytes.toStringBinary(b.array(), b.arrayOffset(), b.position()); WritableUtils.writeVLong(dos, l); String baosStr = Bytes.toStringBinary(baos.toByteArray()); assertEquals(baosStr, bufStr); } }
ByteBufferUtils.writeVLong(dest, memstoreTS); } catch (IOException ex) { throw new RuntimeException("Unable to copy memstore timestamp " +
/** * Convert list of KeyValues to byte buffer. * @param keyValues list of KeyValues to be converted. * @return buffer with content from key values */ public static ByteBuffer convertKvToByteBuffer(List<KeyValue> keyValues, boolean includesMemstoreTS) { int totalSize = 0; for (KeyValue kv : keyValues) { totalSize += kv.getLength(); if (includesMemstoreTS) { totalSize += WritableUtils.getVIntSize(kv.getSequenceId()); } } ByteBuffer result = ByteBuffer.allocate(totalSize); for (KeyValue kv : keyValues) { result.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includesMemstoreTS) { ByteBufferUtils.writeVLong(result, kv.getSequenceId()); } } return result; }
protected final void afterDecodingKeyValue(DataInputStream source, ByteBuffer dest, boolean includesMemstoreTS) { if (includesMemstoreTS) { long memstoreTS = -1; try { // Copy memstore timestamp from the data input stream to the byte // buffer. memstoreTS = WritableUtils.readVLong(source); ByteBufferUtils.writeVLong(dest, memstoreTS); } catch (IOException ex) { throw new RuntimeException("Unable to copy memstore timestamp " + memstoreTS + " after decoding a key/value"); } } }
public static void appendToByteBuffer(final ByteBuffer bb, final KeyValue kv, final boolean includeMvccVersion) { // keep pushing the limit out. assume enough capacity bb.limit(bb.position() + kv.getLength()); bb.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includeMvccVersion) { int numMvccVersionBytes = WritableUtils.getVIntSize(kv.getSequenceId()); ByteBufferUtils.extendLimit(bb, numMvccVersionBytes); ByteBufferUtils.writeVLong(bb, kv.getSequenceId()); } }
public static void appendToByteBuffer(final ByteBuffer bb, final KeyValue kv, final boolean includeMvccVersion) { // keep pushing the limit out. assume enough capacity bb.limit(bb.position() + kv.getLength()); bb.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includeMvccVersion) { int numMvccVersionBytes = WritableUtils.getVIntSize(kv.getMvccVersion()); ByteBufferUtils.extendLimit(bb, numMvccVersionBytes); ByteBufferUtils.writeVLong(bb, kv.getMvccVersion()); } }
public static void appendToByteBuffer(final ByteBuffer bb, final KeyValue kv, final boolean includeMvccVersion) { // keep pushing the limit out. assume enough capacity bb.limit(bb.position() + kv.getLength()); bb.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includeMvccVersion) { int numMvccVersionBytes = WritableUtils.getVIntSize(kv.getSequenceId()); ByteBufferUtils.extendLimit(bb, numMvccVersionBytes); ByteBufferUtils.writeVLong(bb, kv.getSequenceId()); } }
@Test public void testConsistencyWithHadoopVLong() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (long l : testNumbers) { baos.reset(); ByteBuffer b = ByteBuffer.allocate(MAX_VLONG_LENGTH); ByteBufferUtils.writeVLong(b, l); String bufStr = Bytes.toStringBinary(b.array(), b.arrayOffset(), b.position()); WritableUtils.writeVLong(dos, l); String baosStr = Bytes.toStringBinary(baos.toByteArray()); assertEquals(baosStr, bufStr); } }
@Test public void testReadWriteVLong() { for (long l : testNumbers) { ByteBuffer b = ByteBuffer.allocate(MAX_VLONG_LENGTH); ByteBufferUtils.writeVLong(b, l); b.flip(); assertEquals(l, ByteBufferUtils.readVLong(b)); } }
@Test public void testReadWriteVLong() { for (long l : testNumbers) { ByteBuffer b = ByteBuffer.allocate(MAX_VLONG_LENGTH); ByteBufferUtils.writeVLong(b, l); b.flip(); assertEquals(l, ByteBufferUtils.readVLong(b)); } }
@Test public void testConsistencyWithHadoopVLong() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (long l : testNumbers) { baos.reset(); ByteBuffer b = ByteBuffer.allocate(MAX_VLONG_LENGTH); ByteBufferUtils.writeVLong(b, l); String bufStr = Bytes.toStringBinary(b.array(), b.arrayOffset(), b.position()); WritableUtils.writeVLong(dos, l); String baosStr = Bytes.toStringBinary(baos.toByteArray()); assertEquals(baosStr, bufStr); } }
/** * Convert list of KeyValues to byte buffer. * @param keyValues list of KeyValues to be converted. * @return buffer with content from key values */ public static ByteBuffer convertKvToByteBuffer(List<KeyValue> keyValues, boolean includesMemstoreTS) { int totalSize = 0; for (KeyValue kv : keyValues) { totalSize += kv.getLength(); if (includesMemstoreTS) { totalSize += WritableUtils.getVIntSize(kv.getMvccVersion()); } } ByteBuffer result = ByteBuffer.allocate(totalSize); for (KeyValue kv : keyValues) { result.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includesMemstoreTS) { ByteBufferUtils.writeVLong(result, kv.getMvccVersion()); } } return result; }
offset += keyValueLength; if (includesMvcc) { ByteBufferUtils.writeVLong(result, currentCell.getMvccVersion());
ByteBufferUtils.writeVLong(dest, memstoreTS); } catch (IOException ex) { throw new RuntimeException("Unable to copy memstore timestamp " +
ByteBufferUtils.writeVLong(dest, memstoreTS); } catch (IOException ex) { throw new RuntimeException("Unable to copy memstore timestamp " +
ByteBufferUtils.writeVLong(dest, memstoreTS); } catch (IOException ex) { throw new RuntimeException("Unable to copy memstore timestamp " +
/** * Convert list of KeyValues to byte buffer. * @param keyValues list of KeyValues to be converted. * @return buffer with content from key values */ public static ByteBuffer convertKvToByteBuffer(List<KeyValue> keyValues, boolean includesMemstoreTS) { int totalSize = 0; for (KeyValue kv : keyValues) { totalSize += kv.getLength(); if (includesMemstoreTS) { totalSize += WritableUtils.getVIntSize(kv.getSequenceId()); } } ByteBuffer result = ByteBuffer.allocate(totalSize); for (KeyValue kv : keyValues) { result.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includesMemstoreTS) { ByteBufferUtils.writeVLong(result, kv.getSequenceId()); } } return result; }
/** * Convert list of KeyValues to byte buffer. * @param keyValues list of KeyValues to be converted. * @return buffer with content from key values */ public static ByteBuffer convertKvToByteBuffer(List<KeyValue> keyValues, boolean includesMemstoreTS) { int totalSize = 0; for (KeyValue kv : keyValues) { totalSize += kv.getLength(); if (includesMemstoreTS) { totalSize += WritableUtils.getVIntSize(kv.getSequenceId()); } } ByteBuffer result = ByteBuffer.allocate(totalSize); for (KeyValue kv : keyValues) { result.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); if (includesMemstoreTS) { ByteBufferUtils.writeVLong(result, kv.getSequenceId()); } } return result; }