Java 类org.apache.hadoop.hbase.io.hfile.HFileBlock.Writer.BufferGrabbingByteArrayOutputStream 实例源码

项目:ditb    文件:TestHFileDataBlockEncoder.java   
private HFileBlock createBlockOnDisk(List<KeyValue> kvs, HFileBlock block, boolean useTags)
    throws IOException {
  int size;
  HFileBlockEncodingContext context = new HFileBlockDefaultEncodingContext(
      blockEncoder.getDataBlockEncoding(), HConstants.HFILEBLOCK_DUMMY_HEADER,
      block.getHFileContext());

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  baos.write(block.getDummyHeaderForVersion());
  DataOutputStream dos = new DataOutputStream(baos);
  blockEncoder.startBlockEncoding(context, dos);
  for (KeyValue kv : kvs) {
    blockEncoder.encode(kv, context, dos);
  }
  BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
  baos.writeTo(stream);
  blockEncoder.endBlockEncoding(context, dos, stream.getBuffer(), BlockType.DATA);
  byte[] encodedBytes = baos.toByteArray();
  size = encodedBytes.length - block.getDummyHeaderForVersion().length;
  return new HFileBlock(context.getBlockType(), size, size, -1, ByteBuffer.wrap(encodedBytes),
      HFileBlock.FILL_HEADER, 0, block.getOnDiskDataSizeWithHeader(), block.getHFileContext());
}
项目:ditb    文件:TestDataBlockEncoders.java   
static ByteBuffer encodeKeyValues(DataBlockEncoding encoding, List<KeyValue> kvs,
    HFileBlockEncodingContext encodingContext) throws IOException {
  DataBlockEncoder encoder = encoding.getEncoder();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
  DataOutputStream dos = new DataOutputStream(baos);
  encoder.startBlockEncoding(encodingContext, dos);
  for (KeyValue kv : kvs) {
    encoder.encode(kv, encodingContext, dos);
  }
  BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
  baos.writeTo(stream);
  encoder.endBlockEncoding(encodingContext, dos, stream.getBuffer());
  byte[] encodedData = new byte[baos.size() - ENCODED_DATA_OFFSET];
  System.arraycopy(baos.toByteArray(), ENCODED_DATA_OFFSET, encodedData, 0, encodedData.length);
  return ByteBuffer.wrap(encodedData);
}
项目:pbase    文件:TestHFileDataBlockEncoder.java   
private HFileBlock createBlockOnDisk(List<KeyValue> kvs, HFileBlock block, boolean useTags)
    throws IOException {
  int size;
  HFileBlockEncodingContext context = new HFileBlockDefaultEncodingContext(
      blockEncoder.getDataBlockEncoding(), HConstants.HFILEBLOCK_DUMMY_HEADER,
      block.getHFileContext());

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  baos.write(block.getDummyHeaderForVersion());
  DataOutputStream dos = new DataOutputStream(baos);
  blockEncoder.startBlockEncoding(context, dos);
  for (KeyValue kv : kvs) {
    blockEncoder.encode(kv, context, dos);
  }
  BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
  baos.writeTo(stream);
  blockEncoder.endBlockEncoding(context, dos, stream.getBuffer(), BlockType.DATA);
  byte[] encodedBytes = baos.toByteArray();
  size = encodedBytes.length - block.getDummyHeaderForVersion().length;
  return new HFileBlock(context.getBlockType(), size, size, -1, ByteBuffer.wrap(encodedBytes),
      HFileBlock.FILL_HEADER, 0, block.getOnDiskDataSizeWithHeader(), block.getHFileContext());
}
项目:pbase    文件:TestDataBlockEncoders.java   
static ByteBuffer encodeKeyValues(DataBlockEncoding encoding, List<KeyValue> kvs,
    HFileBlockEncodingContext encodingContext) throws IOException {
  DataBlockEncoder encoder = encoding.getEncoder();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
  DataOutputStream dos = new DataOutputStream(baos);
  encoder.startBlockEncoding(encodingContext, dos);
  for (KeyValue kv : kvs) {
    encoder.encode(kv, encodingContext, dos);
  }
  BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
  baos.writeTo(stream);
  encoder.endBlockEncoding(encodingContext, dos, stream.getBuffer());
  byte[] encodedData = new byte[baos.size() - ENCODED_DATA_OFFSET];
  System.arraycopy(baos.toByteArray(), ENCODED_DATA_OFFSET, encodedData, 0, encodedData.length);
  return ByteBuffer.wrap(encodedData);
}
项目:PyroDB    文件:TestHFileDataBlockEncoder.java   
private HFileBlock createBlockOnDisk(List<KeyValue> kvs, HFileBlock block, boolean useTags)
    throws IOException {
  int size;
  HFileBlockEncodingContext context = new HFileBlockDefaultEncodingContext(
      blockEncoder.getDataBlockEncoding(), HConstants.HFILEBLOCK_DUMMY_HEADER,
      block.getHFileContext());

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  baos.write(block.getDummyHeaderForVersion());
  DataOutputStream dos = new DataOutputStream(baos);
  blockEncoder.startBlockEncoding(context, dos);
  for (KeyValue kv : kvs) {
    blockEncoder.encode(kv, context, dos);
  }
  BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
  baos.writeTo(stream);
  blockEncoder.endBlockEncoding(context, dos, stream.getBuffer(), BlockType.DATA);
  byte[] encodedBytes = baos.toByteArray();
  size = encodedBytes.length - block.getDummyHeaderForVersion().length;
  return new HFileBlock(context.getBlockType(), size, size, -1, ByteBuffer.wrap(encodedBytes),
      HFileBlock.FILL_HEADER, 0, block.getOnDiskDataSizeWithHeader(), block.getHFileContext());
}
项目:PyroDB    文件:TestDataBlockEncoders.java   
static ByteBuffer encodeKeyValues(DataBlockEncoding encoding, List<KeyValue> kvs,
    HFileBlockEncodingContext encodingContext) throws IOException {
  DataBlockEncoder encoder = encoding.getEncoder();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
  DataOutputStream dos = new DataOutputStream(baos);
  encoder.startBlockEncoding(encodingContext, dos);
  for (KeyValue kv : kvs) {
    encoder.encode(kv, encodingContext, dos);
  }
  BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
  baos.writeTo(stream);
  encoder.endBlockEncoding(encodingContext, dos, stream.getBuffer());
  byte[] encodedData = new byte[baos.size() - ENCODED_DATA_OFFSET];
  System.arraycopy(baos.toByteArray(), ENCODED_DATA_OFFSET, encodedData, 0, encodedData.length);
  return ByteBuffer.wrap(encodedData);
}
项目:ditb    文件:TestDataBlockEncoders.java   
private void testEncodersOnDataset(List<KeyValue> kvList, boolean includesMemstoreTS,
    boolean includesTags) throws IOException {
  ByteBuffer unencodedDataBuf = RedundantKVGenerator.convertKvToByteBuffer(kvList,
      includesMemstoreTS);
  HFileContext fileContext = new HFileContextBuilder().withIncludesMvcc(includesMemstoreTS)
      .withIncludesTags(includesTags).build();
  for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
    DataBlockEncoder encoder = encoding.getEncoder();
    if (encoder == null) {
      continue;
    }
    HFileBlockEncodingContext encodingContext = new HFileBlockDefaultEncodingContext(encoding,
        HConstants.HFILEBLOCK_DUMMY_HEADER, fileContext);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
    DataOutputStream dos = new DataOutputStream(baos);
    encoder.startBlockEncoding(encodingContext, dos);
    for (KeyValue kv : kvList) {
      encoder.encode(kv, encodingContext, dos);
    }
    BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
    baos.writeTo(stream);
    encoder.endBlockEncoding(encodingContext, dos, stream.getBuffer());
    byte[] encodedData = baos.toByteArray();

    testAlgorithm(encodedData, unencodedDataBuf, encoder);
  }
}
项目:pbase    文件:TestDataBlockEncoders.java   
private void testEncodersOnDataset(List<KeyValue> kvList, boolean includesMemstoreTS,
    boolean includesTags) throws IOException {
  ByteBuffer unencodedDataBuf = RedundantKVGenerator.convertKvToByteBuffer(kvList,
      includesMemstoreTS);
  HFileContext fileContext = new HFileContextBuilder().withIncludesMvcc(includesMemstoreTS)
      .withIncludesTags(includesTags).build();
  for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
    DataBlockEncoder encoder = encoding.getEncoder();
    if (encoder == null) {
      continue;
    }
    HFileBlockEncodingContext encodingContext = new HFileBlockDefaultEncodingContext(encoding,
        HConstants.HFILEBLOCK_DUMMY_HEADER, fileContext);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
    DataOutputStream dos = new DataOutputStream(baos);
    encoder.startBlockEncoding(encodingContext, dos);
    for (KeyValue kv : kvList) {
      encoder.encode(kv, encodingContext, dos);
    }
    BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
    baos.writeTo(stream);
    encoder.endBlockEncoding(encodingContext, dos, stream.getBuffer());
    byte[] encodedData = baos.toByteArray();

    testAlgorithm(encodedData, unencodedDataBuf, encoder);
  }
}
项目:PyroDB    文件:TestDataBlockEncoders.java   
private void testEncodersOnDataset(List<KeyValue> kvList, boolean includesMemstoreTS,
    boolean includesTags) throws IOException {
  ByteBuffer unencodedDataBuf = RedundantKVGenerator.convertKvToByteBuffer(kvList,
      includesMemstoreTS);
  HFileContext fileContext = new HFileContextBuilder().withIncludesMvcc(includesMemstoreTS)
      .withIncludesTags(includesTags).build();
  for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
    DataBlockEncoder encoder = encoding.getEncoder();
    if (encoder == null) {
      continue;
    }
    HFileBlockEncodingContext encodingContext = new HFileBlockDefaultEncodingContext(encoding,
        HConstants.HFILEBLOCK_DUMMY_HEADER, fileContext);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
    DataOutputStream dos = new DataOutputStream(baos);
    encoder.startBlockEncoding(encodingContext, dos);
    for (KeyValue kv : kvList) {
      encoder.encode(kv, encodingContext, dos);
    }
    BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
    baos.writeTo(stream);
    encoder.endBlockEncoding(encodingContext, dos, stream.getBuffer());
    byte[] encodedData = baos.toByteArray();

    testAlgorithm(encodedData, unencodedDataBuf, encoder);
  }
}