/** * Read integer from buffer coded in 7 bits and increment position. * @return Read integer. */ public static int readCompressedInt(ByteBuffer buffer) { byte b = buffer.get(); if ((b & NEXT_BIT_MASK) != 0) { return (b & VALUE_MASK) + (readCompressedInt(buffer) << NEXT_BIT_SHIFT); } return b & VALUE_MASK; }
private int decodeKeyValue(DataInputStream source, ByteBuffer buffer, int prevKeyOffset) throws IOException, EncoderBufferTooSmallException { int keyLength = ByteBufferUtils.readCompressedInt(source); int valueLength = ByteBufferUtils.readCompressedInt(source); int commonLength = ByteBufferUtils.readCompressedInt(source); int keyOffset; keyLength += commonLength; ensureSpace(buffer, keyLength + valueLength + KeyValue.ROW_OFFSET); buffer.putInt(keyLength); buffer.putInt(valueLength); // copy the prefix if (commonLength > 0) { keyOffset = buffer.position(); ByteBufferUtils.copyFromBufferToBuffer(buffer, buffer, prevKeyOffset, commonLength); } else { keyOffset = buffer.position(); } // copy rest of the key and value int len = keyLength - commonLength + valueLength; ByteBufferUtils.copyFromStreamToBuffer(buffer, source, len); return keyOffset; }
private void testCompressedInt(int value) throws IOException { int parsedValue = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteBufferUtils.putCompressedInt(bos, value); ByteArrayInputStream bis = new ByteArrayInputStream( bos.toByteArray()); parsedValue = ByteBufferUtils.readCompressedInt(bis); assertEquals(value, parsedValue); }
keyLength = state.keyLength; } else { keyLength = ByteBufferUtils.readCompressedInt(source); valueLength = ByteBufferUtils.readCompressedInt(source); int commonPrefix = ByteBufferUtils.readCompressedInt(source);
state.keyLength = ByteBufferUtils.readCompressedInt(source); state.valueLength = ByteBufferUtils.readCompressedInt(source); int commonLength = ByteBufferUtils.readCompressedInt(source);
protected final void afterDecodingKeyValue(DataInputStream source, ByteBuffer dest, HFileBlockDefaultDecodingContext decodingCtx) throws IOException { if (decodingCtx.getHFileContext().isIncludesTags()) { int tagsLength = ByteBufferUtils.readCompressedInt(source);
/** * Read integer from buffer coded in 7 bits and increment position. * @return Read integer. */ public static int readCompressedInt(ByteBuffer buffer) { byte b = buffer.get(); if ((b & NEXT_BIT_MASK) != 0) { return (b & VALUE_MASK) + (readCompressedInt(buffer) << NEXT_BIT_SHIFT); } return b & VALUE_MASK; }
/** * Read integer from buffer coded in 7 bits and increment position. * @return Read integer. */ public static int readCompressedInt(ByteBuffer buffer) { byte b = buffer.get(); if ((b & NEXT_BIT_MASK) != 0) { return (b & VALUE_MASK) + (readCompressedInt(buffer) << NEXT_BIT_SHIFT); } return b & VALUE_MASK; }
/** * Read integer from buffer coded in 7 bits and increment position. * @return Read integer. */ public static int readCompressedInt(ByteBuffer buffer) { byte b = buffer.get(); if ((b & NEXT_BIT_MASK) != 0) { return (b & VALUE_MASK) + (readCompressedInt(buffer) << NEXT_BIT_SHIFT); } return b & VALUE_MASK; }
/** * Read integer from buffer coded in 7 bits and increment position. * @return Read integer. */ public static int readCompressedInt(ByteBuffer buffer) { byte b = buffer.get(); if ((b & NEXT_BIT_MASK) != 0) { return (b & VALUE_MASK) + (readCompressedInt(buffer) << NEXT_BIT_SHIFT); } return b & VALUE_MASK; }
@Override public ByteBuffer getFirstKeyInBlock(ByteBuffer block) { block.mark(); block.position(Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE); int keyLength = ByteBufferUtils.readCompressedInt(block); ByteBufferUtils.readCompressedInt(block); // valueLength ByteBufferUtils.readCompressedInt(block); // commonLength int pos = block.position(); block.reset(); return ByteBuffer.wrap(block.array(), pos, keyLength).slice(); }
@Override public ByteBuffer getFirstKeyInBlock(ByteBuffer block) { block.mark(); block.position(Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE); int keyLength = ByteBufferUtils.readCompressedInt(block); ByteBufferUtils.readCompressedInt(block); // valueLength ByteBufferUtils.readCompressedInt(block); // commonLength int pos = block.position(); block.reset(); ByteBuffer dup = block.duplicate(); dup.position(pos); dup.limit(pos + keyLength); return dup.slice(); }
@Override public ByteBuffer getFirstKeyInBlock(ByteBuffer block) { block.mark(); block.position(Bytes.SIZEOF_INT); int keyLength = ByteBufferUtils.readCompressedInt(block); ByteBufferUtils.readCompressedInt(block); int commonLength = ByteBufferUtils.readCompressedInt(block); if (commonLength != 0) { throw new AssertionError("Nonzero common length in the first key in " + "block: " + commonLength); } int pos = block.position(); block.reset(); return ByteBuffer.wrap(block.array(), pos, keyLength).slice(); }
@Override public ByteBuffer getFirstKeyInBlock(ByteBuffer block) { block.mark(); block.position(Bytes.SIZEOF_INT); int keyLength = ByteBufferUtils.readCompressedInt(block); ByteBufferUtils.readCompressedInt(block); int commonLength = ByteBufferUtils.readCompressedInt(block); if (commonLength != 0) { throw new AssertionError("Nonzero common length in the first key in " + "block: " + commonLength); } int pos = block.position(); block.reset(); ByteBuffer dup = block.duplicate(); dup.position(pos); dup.limit(pos + keyLength); return dup.slice(); }
@Override protected void decodeNext() { current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer); current.valueLength = ByteBufferUtils.readCompressedInt(currentBuffer); current.lastCommonPrefix = ByteBufferUtils.readCompressedInt(currentBuffer); current.keyLength += current.lastCommonPrefix; current.ensureSpaceForKey(); currentBuffer.get(current.keyBuffer, current.lastCommonPrefix, current.keyLength - current.lastCommonPrefix); current.valueOffset = currentBuffer.position(); ByteBufferUtils.skip(currentBuffer, current.valueLength); if (includesMemstoreTS) { current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer); } else { current.memstoreTS = 0; } current.nextKvOffset = currentBuffer.position(); }
private int decodeKeyValue(DataInputStream source, ByteBuffer buffer, int prevKeyOffset) throws IOException, EncoderBufferTooSmallException { int keyLength = ByteBufferUtils.readCompressedInt(source); int valueLength = ByteBufferUtils.readCompressedInt(source); int commonLength = ByteBufferUtils.readCompressedInt(source); int keyOffset; keyLength += commonLength; ensureSpace(buffer, keyLength + valueLength + KeyValue.ROW_OFFSET); buffer.putInt(keyLength); buffer.putInt(valueLength); // copy the prefix if (commonLength > 0) { keyOffset = buffer.position(); ByteBufferUtils.copyFromBufferToBuffer(buffer, buffer, prevKeyOffset, commonLength); } else { keyOffset = buffer.position(); } // copy rest of the key and value int len = keyLength - commonLength + valueLength; ByteBufferUtils.copyFromStreamToBuffer(buffer, source, len); return keyOffset; }
private int uncompressKeyValue(DataInputStream source, ByteBuffer buffer, int prevKeyOffset) throws IOException, EncoderBufferTooSmallException { int keyLength = ByteBufferUtils.readCompressedInt(source); int valueLength = ByteBufferUtils.readCompressedInt(source); int commonLength = ByteBufferUtils.readCompressedInt(source); int keyOffset; keyLength += commonLength; ByteBufferUtils.ensureSpace(buffer, keyLength + valueLength + KeyValue.ROW_OFFSET); buffer.putInt(keyLength); buffer.putInt(valueLength); // copy the prefix if (commonLength > 0) { keyOffset = buffer.position(); ByteBufferUtils.copyFromBufferToBuffer(buffer, buffer, prevKeyOffset, commonLength); } else { keyOffset = buffer.position(); } // copy rest of the key and value int len = keyLength - commonLength + valueLength; ByteBufferUtils.copyFromStreamToBuffer(buffer, source, len); return keyOffset; }
@Override protected void decodeNext() { current.keyLength = ByteBufferUtils.readCompressedInt(currentBuffer); current.valueLength = ByteBufferUtils.readCompressedInt(currentBuffer); current.lastCommonPrefix = ByteBufferUtils.readCompressedInt(currentBuffer); current.keyLength += current.lastCommonPrefix; current.ensureSpaceForKey(); currentBuffer.get(current.keyBuffer, current.lastCommonPrefix, current.keyLength - current.lastCommonPrefix); current.valueOffset = currentBuffer.position(); ByteBufferUtils.skip(currentBuffer, current.valueLength); if (includesTags()) { decodeTags(); } if (includesMvcc()) { current.memstoreTS = ByteBufferUtils.readVLong(currentBuffer); } else { current.memstoreTS = 0; } current.nextKvOffset = currentBuffer.position(); }
private void testCompressedInt(int value) throws IOException { int parsedValue = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteBufferUtils.putCompressedInt(bos, value); ByteArrayInputStream bis = new ByteArrayInputStream( bos.toByteArray()); parsedValue = ByteBufferUtils.readCompressedInt(bis); assertEquals(value, parsedValue); }
private void testCompressedInt(int value) throws IOException { int parsedValue = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteBufferUtils.putCompressedInt(bos, value); ByteArrayInputStream bis = new ByteArrayInputStream( bos.toByteArray()); parsedValue = ByteBufferUtils.readCompressedInt(bis); assertEquals(value, parsedValue); }