code: void close(ByteBuf out) {
          // If an RLE run is in progress, write it out
          if (rleLength > 0) {
              writeRun(rleCurrentValue & 0xff, rleLength);
          }
  
          // Apply a one byte block wrap required by the BWT implementation
          block[blockLength] = block[0];
  
          // Perform the Burrows Wheeler Transform
          Bzip2DivSufSort divSufSort = new Bzip2DivSufSort(block, bwtBlock, blockLength);
          int bwtStartPointer = divSufSort.bwt();
  
          Bzip2BitWriter writer = this.writer;
  
          // Write out the block header
          writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_1);
          writer.writeBits(out, 24, BLOCK_HEADER_MAGIC_2);
          writer.writeInt(out, crc.getCRC());
          writer.writeBoolean(out, false); // Randomised block flag. We never create randomised blocks
          writer.writeBits(out, 24, bwtStartPointer);
  
          // Write out the symbol map
          writeSymbolMap(out);
  
          // Perform the Move To Front Transform and Run-Length Encoding[2] stages
          Bzip2MTFAndRLE2StageEncoder mtfEncoder = new Bzip2MTFAndRLE2StageEncoder(bwtBlock, blockLength,
                                                                                      blockValuesPresent);
          mtfEncoder.encode();
  
          // Perform the Huffman Encoding stage and write out the encoded data
          Bzip2HuffmanStageEncoder huffmanEncoder = new Bzip2HuffmanStageEncoder(writer,
                  mtfEncoder.mtfBlock(),
                  mtfEncoder.mtfLength(),
                  mtfEncoder.mtfAlphabetSize(),
                  mtfEncoder.mtfSymbolFrequencies());
          huffmanEncoder.encode(out);
      }
docs: Compresses and writes out the block.