@Override public CachedData encode(HFileBlock block) { ByteBuffer bb = ByteBuffer.allocate(block.getSerializedLength()); block.serialize(bb, true); return new CachedData(0, bb.array(), CachedData.MAX_SIZE); }
@Test public void testSerializeWithoutNextBlockMetadata() { int size = 100; int length = HConstants.HFILEBLOCK_HEADER_SIZE + size; byte[] byteArr = new byte[length]; ByteBuffer buf = ByteBuffer.wrap(byteArr, 0, size); HFileContext meta = new HFileContextBuilder().build(); HFileBlock blockWithNextBlockMetadata = new HFileBlock(BlockType.DATA, size, size, -1, buf, HFileBlock.FILL_HEADER, -1, 52, -1, meta); HFileBlock blockWithoutNextBlockMetadata = new HFileBlock(BlockType.DATA, size, size, -1, buf, HFileBlock.FILL_HEADER, -1, -1, -1, meta); ByteBuffer buff1 = ByteBuffer.allocate(length); ByteBuffer buff2 = ByteBuffer.allocate(length); blockWithNextBlockMetadata.serialize(buff1, true); blockWithoutNextBlockMetadata.serialize(buff2, true); assertNotEquals(buff1, buff2); buff1.clear(); buff2.clear(); blockWithNextBlockMetadata.serialize(buff1, false); blockWithoutNextBlockMetadata.serialize(buff2, false); assertEquals(buff1, buff2); } }
blockFromHFile.serialize(serialized, true); HFileBlock deserialized = (HFileBlock) blockFromHFile.getDeserializer().deserialize(
@Override public CachedData encode(HFileBlock block) { ByteBuffer bb = ByteBuffer.allocate(block.getSerializedLength()); block.serialize(bb); return new CachedData(0, bb.array(), CachedData.MAX_SIZE); }
@Test public void testSerializeWithoutNextBlockMetadata() { int size = 100; int length = HConstants.HFILEBLOCK_HEADER_SIZE + size; byte[] byteArr = new byte[length]; ByteBuffer buf = ByteBuffer.wrap(byteArr, 0, size); HFileContext meta = new HFileContextBuilder().build(); HFileBlock blockWithNextBlockMetadata = new HFileBlock(BlockType.DATA, size, size, -1, buf, HFileBlock.FILL_HEADER, -1, 52, -1, meta); HFileBlock blockWithoutNextBlockMetadata = new HFileBlock(BlockType.DATA, size, size, -1, buf, HFileBlock.FILL_HEADER, -1, -1, -1, meta); ByteBuffer buff1 = ByteBuffer.allocate(length); ByteBuffer buff2 = ByteBuffer.allocate(length); blockWithNextBlockMetadata.serialize(buff1, true); blockWithoutNextBlockMetadata.serialize(buff2, true); assertNotEquals(buff1, buff2); buff1.clear(); buff2.clear(); blockWithNextBlockMetadata.serialize(buff1, false); blockWithoutNextBlockMetadata.serialize(buff2, false); assertEquals(buff1, buff2); } }
blockFromHFile.serialize(serialized, true); HFileBlock deserialized = (HFileBlock) blockFromHFile.getDeserializer().deserialize(