code: @Override
    public void write(DataOutput out) throws IOException {
      super.write(out);
      byte[] bytes = new byte[getNBytes()];
      for(int i = 0, byteIndex = 0, bitIndex = 0; i < vectorSize; i++, bitIndex++) {
        if (bitIndex == 8) {
          bitIndex = 0;
          byteIndex++;
        }
        if (bitIndex == 0) {
          bytes[byteIndex] = 0;
        }
        if (bits.get(i)) {
          bytes[byteIndex] |= bitvalues[bitIndex];
        }
      }
      out.write(bytes);
    }
docs: Writable