code: void flush(ByteBuf out) {
          final int bitCount = this.bitCount;
  
          if (bitCount > 0) {
              final long bitBuffer = this.bitBuffer;
              final int shiftToRight = 64 - bitCount;
  
              if (bitCount <= 8) {
                  out.writeByte((int) (bitBuffer >>> shiftToRight << 8 - bitCount));
              } else if (bitCount <= 16) {
                  out.writeShort((int) (bitBuffer >>> shiftToRight << 16 - bitCount));
              } else if (bitCount <= 24) {
                  out.writeMedium((int) (bitBuffer >>> shiftToRight << 24 - bitCount));
              } else {
                  out.writeInt((int) (bitBuffer >>> shiftToRight << 32 - bitCount));
              }
          }
      }
docs: Writes any remaining bits to the output {@link ByteBuf},
  zero padding to a whole byte as required.