Пример #1
0
 /**
  * Do the encoding, but do not cache the encoded data.
  *
  * @return encoded data block with header and checksum
  */
 public byte[] encodeData() {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   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);
       }
       if (this.meta.isIncludesMvcc()) {
         memstoreTS = ByteBufferUtils.readVLong(in);
       }
       kv =
           new KeyValue(
               in.array(),
               kvOffset,
               (int) KeyValue.getKeyValueDataStructureSize(klength, vlength, tagsLength));
       kv.setSequenceId(memstoreTS);
       this.dataBlockEncoder.encode(kv, encodingCtx, out);
     }
     BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
     baos.writeTo(stream);
     this.dataBlockEncoder.endBlockEncoding(encodingCtx, out, stream.buf);
   } 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 baos.toByteArray();
 }