public byte[] encodeData() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] baosBytes = null;
    try {
      baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
      DataOutputStream out = new DataOutputStream(baos);
      this.dataBlockEncoder.startBlockEncoding(encodingCtx, out);
      ByteBuffer in = getUncompressedBuffer();
      in.rewind();
      int klength, vlength;
      int tagsLength = 0;
      long memstoreTS = 0L;
      KeyValue kv = null;
      while (in.hasRemaining()) {
        int kvOffset = in.position();
        klength = in.getInt();
        vlength = in.getInt();
        ByteBufferUtils.skip(in, klength + vlength);
        if (this.meta.isIncludesTags()) {
          tagsLength = ((in.get() & 0xff) << 8) ^ (in.get() & 0xff);
          ByteBufferUtils.skip(in, tagsLength);
          this.isTagsLenZero.add(tagsLength == 0);
        }
        if (this.meta.isIncludesMvcc()) {
          memstoreTS = ByteBufferUtils.readVLong(in);
        }
        kv = new KeyValue(in.array(), in.arrayOffset() + kvOffset,
          (int) KeyValue.getKeyValueDataStructureSize(klength, vlength, tagsLength));
        kv.setSequenceId(memstoreTS);
        this.dataBlockEncoder.encode(kv, encodingCtx, out);
      }
      // Below depends on BAOS internal behavior. toByteArray makes a copy of bytes so far.
      baos.flush();
      baosBytes = baos.toByteArray();
      this.dataBlockEncoder.endBlockEncoding(encodingCtx, out, baosBytes);
      // In endBlockEncoding(encodingCtx, out, baosBytes), Encoder ROW_INDEX_V1 write integer in
      // out while the others write integer in baosBytes(byte array). We need to add
      // baos.toByteArray() after endBlockEncoding again to make sure the integer writes in
      // outputstream with Encoder ROW_INDEX_V1 dump to byte array (baosBytes).
      // The if branch is necessary because Encoders excepts ROW_INDEX_V1 write integer in
      // baosBytes directly, without if branch and do toByteArray() again, baosBytes won't
      // contains the integer wrotten in endBlockEncoding.
      if (this.encoding.equals(DataBlockEncoding.ROW_INDEX_V1)) {
        baosBytes = baos.toByteArray();
      }
    } catch (IOException e) {
      throw new RuntimeException(String.format("Bug in encoding part of algorithm %s. "
        + "Probably it requested more bytes than are available.", toString()), e);
    }
    return baosBytes;
  }
Do the encoding, but do not cache the encoded data.
@return encoded data block with header and checksum
hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/EncodedDataBlock.java