@Override protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength, int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException { int decompressedSize = source.readInt(); ByteBuffer buffer = ByteBuffer.allocate(decompressedSize + allocateHeaderLength); buffer.position(allocateHeaderLength); ByteBufferUtils.copyFromStreamToBuffer(buffer, source, decompressedSize); return buffer; } }
/** * Copies the first key/value from the given stream, and initializes * decompression state based on it. Assumes that we have already read key * and value lengths. Does not set {@link #qualifierLength} (not used by * decompression) or {@link #prevOffset} (set by the calle afterwards). */ private void decompressFirstKV(ByteBuffer out, DataInputStream in) throws IOException { int kvPos = out.position(); out.putInt(keyLength); out.putInt(valueLength); prevTimestampOffset = out.position() + keyLength - KeyValue.TIMESTAMP_TYPE_SIZE; ByteBufferUtils.copyFromStreamToBuffer(out, in, keyLength + valueLength); rowLength = out.getShort(kvPos + KeyValue.ROW_OFFSET); familyLength = out.get(kvPos + KeyValue.ROW_OFFSET + KeyValue.ROW_LENGTH_SIZE + rowLength); type = out.get(prevTimestampOffset + KeyValue.TIMESTAMP_SIZE); }
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; }
/** * Test copying data from stream. * @throws IOException On test failure. */ @Test public void testCopyFromStream() throws IOException { ByteBuffer buffer = ByteBuffer.allocate(array.length); ByteArrayInputStream bis = new ByteArrayInputStream(array); DataInputStream dis = new DataInputStream(bis); ByteBufferUtils.copyFromStreamToBuffer(buffer, dis, array.length / 2); ByteBufferUtils.copyFromStreamToBuffer(buffer, dis, array.length - array.length / 2); for (int i = 0; i < array.length; ++i) { assertEquals(array[i], buffer.get(i)); } }
ByteBufferUtils.copyFromStreamToBuffer(out, source, KeyValue.ROW_LENGTH_SIZE - commonLength); ByteBufferUtils.copyFromStreamToBuffer(out, source, rowRestLength); ByteBufferUtils.copyFromStreamToBuffer(out, source, keyRestLength); state.prevTimestampOffset, prefixTimestamp); state.prevTimestampOffset = out.position() - prefixTimestamp; ByteBufferUtils.copyFromStreamToBuffer(out, source, KeyValue.TIMESTAMP_SIZE - prefixTimestamp); KeyValue.ROW_OFFSET + prevKeyLength, state.valueLength); } else { ByteBufferUtils.copyFromStreamToBuffer(out, source, state.valueLength); ByteBufferUtils.copyFromStreamToBuffer(out, source, KeyValue.TYPE_SIZE); ByteBufferUtils.copyFromBufferToBuffer(out, out, state.prevOffset + KeyValue.ROW_OFFSET + prevKeyLength, state.valueLength); } else { ByteBufferUtils.copyFromStreamToBuffer(out, source, state.valueLength + KeyValue.TYPE_SIZE);
ByteBufferUtils.copyFromStreamToBuffer(buffer, source, KeyValue.ROW_LENGTH_SIZE - commonPrefix); ByteBufferUtils.skip(buffer, -KeyValue.ROW_LENGTH_SIZE); ByteBufferUtils.copyFromStreamToBuffer(buffer, source, rowRestLength); state.rowLength = rowLength; ByteBufferUtils.copyFromStreamToBuffer(buffer, source, keyRestLength); ByteBufferUtils.copyFromStreamToBuffer(buffer, source, valueLength);
tagCompressionContext.uncompressTags(source, dest, tagsLength); } else { ByteBufferUtils.copyFromStreamToBuffer(dest, source, tagsLength);
@Override protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength, int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException { int decompressedSize = source.readInt(); ByteBuffer buffer = ByteBuffer.allocate(decompressedSize + allocateHeaderLength); buffer.position(allocateHeaderLength); ByteBufferUtils.copyFromStreamToBuffer(buffer, source, decompressedSize); return buffer; } }
@Override protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength, int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException { int decompressedSize = source.readInt(); ByteBuffer buffer = ByteBuffer.allocate(decompressedSize + allocateHeaderLength); buffer.position(allocateHeaderLength); ByteBufferUtils.copyFromStreamToBuffer(buffer, source, decompressedSize); return buffer; } }
@Override public ByteBuffer uncompressKeyValues(DataInputStream source, int preserveHeaderLength, int skipLastBytes, boolean includesMemstoreTS) throws IOException { int decompressedSize = source.readInt(); ByteBuffer buffer = ByteBuffer.allocate(decompressedSize + preserveHeaderLength); buffer.position(preserveHeaderLength); ByteBufferUtils.copyFromStreamToBuffer(buffer, source, decompressedSize); return buffer; }
@Override protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength, int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException { int decompressedSize = source.readInt(); ByteBuffer buffer = ByteBuffer.allocate(decompressedSize + allocateHeaderLength); buffer.position(allocateHeaderLength); ByteBufferUtils.copyFromStreamToBuffer(buffer, source, decompressedSize); return buffer; } }
/** * Copies the first key/value from the given stream, and initializes * decompression state based on it. Assumes that we have already read key * and value lengths. Does not set {@link #qualifierLength} (not used by * decompression) or {@link #prevOffset} (set by the calle afterwards). */ private void decompressFirstKV(ByteBuffer out, DataInputStream in) throws IOException { int kvPos = out.position(); out.putInt(keyLength); out.putInt(valueLength); prevTimestampOffset = out.position() + keyLength - KeyValue.TIMESTAMP_TYPE_SIZE; ByteBufferUtils.copyFromStreamToBuffer(out, in, keyLength + valueLength); rowLength = out.getShort(kvPos + KeyValue.ROW_OFFSET); familyLength = out.get(kvPos + KeyValue.ROW_OFFSET + KeyValue.ROW_LENGTH_SIZE + rowLength); type = out.get(prevTimestampOffset + KeyValue.TIMESTAMP_SIZE); }
/** * Copies the first key/value from the given stream, and initializes * decompression state based on it. Assumes that we have already read key * and value lengths. Does not set {@link #qualifierLength} (not used by * decompression) or {@link #prevOffset} (set by the calle afterwards). */ private void decompressFirstKV(ByteBuffer out, DataInputStream in) throws IOException { int kvPos = out.position(); out.putInt(keyLength); out.putInt(valueLength); prevTimestampOffset = out.position() + keyLength - KeyValue.TIMESTAMP_TYPE_SIZE; ByteBufferUtils.copyFromStreamToBuffer(out, in, keyLength + valueLength); rowLength = out.getShort(kvPos + KeyValue.ROW_OFFSET); familyLength = out.get(kvPos + KeyValue.ROW_OFFSET + KeyValue.ROW_LENGTH_SIZE + rowLength); type = out.get(prevTimestampOffset + KeyValue.TIMESTAMP_SIZE); }
/** * Copies the first key/value from the given stream, and initializes * decompression state based on it. Assumes that we have already read key * and value lengths. Does not set {@link #qualifierLength} (not used by * decompression) or {@link #prevOffset} (set by the calle afterwards). */ private void decompressFirstKV(ByteBuffer out, DataInputStream in) throws IOException { int kvPos = out.position(); out.putInt(keyLength); out.putInt(valueLength); prevTimestampOffset = out.position() + keyLength - KeyValue.TIMESTAMP_TYPE_SIZE; ByteBufferUtils.copyFromStreamToBuffer(out, in, keyLength + valueLength); rowLength = out.getShort(kvPos + KeyValue.ROW_OFFSET); familyLength = out.get(kvPos + KeyValue.ROW_OFFSET + KeyValue.ROW_LENGTH_SIZE + rowLength); type = out.get(prevTimestampOffset + KeyValue.TIMESTAMP_SIZE); }
/** * Copies the first key/value from the given stream, and initializes * decompression state based on it. Assumes that we have already read key * and value lengths. Does not set {@link #qualifierLength} (not used by * decompression) or {@link #prevOffset} (set by the calle afterwards). */ private void decompressFirstKV(ByteBuffer out, DataInputStream in) throws IOException { int kvPos = out.position(); out.putInt(keyLength); out.putInt(valueLength); prevTimestampOffset = out.position() + keyLength - KeyValue.TIMESTAMP_TYPE_SIZE; ByteBufferUtils.copyFromStreamToBuffer(out, in, keyLength + valueLength); rowLength = out.getShort(kvPos + KeyValue.ROW_OFFSET); familyLength = out.get(kvPos + KeyValue.ROW_OFFSET + KeyValue.ROW_LENGTH_SIZE + rowLength); type = out.get(prevTimestampOffset + KeyValue.TIMESTAMP_SIZE); }
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; }
/** * Test copying data from stream. * @throws IOException On test failure. */ @Test public void testCopyFromStream() throws IOException { ByteBuffer buffer = ByteBuffer.allocate(array.length); ByteArrayInputStream bis = new ByteArrayInputStream(array); DataInputStream dis = new DataInputStream(bis); ByteBufferUtils.copyFromStreamToBuffer(buffer, dis, array.length / 2); ByteBufferUtils.copyFromStreamToBuffer(buffer, dis, array.length - array.length / 2); for (int i = 0; i < array.length; ++i) { assertEquals(array[i], buffer.get(i)); } }
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; }
/** * Test copying data from stream. * @throws IOException On test failure. */ @Test public void testCopyFromStream() throws IOException { ByteBuffer buffer = ByteBuffer.allocate(array.length); ByteArrayInputStream bis = new ByteArrayInputStream(array); DataInputStream dis = new DataInputStream(bis); ByteBufferUtils.copyFromStreamToBuffer(buffer, dis, array.length / 2); ByteBufferUtils.copyFromStreamToBuffer(buffer, dis, array.length - array.length / 2); for (int i = 0; i < array.length; ++i) { assertEquals(array[i], buffer.get(i)); } }