private void writeKeyValues(int entryCount, boolean useTags, HFile.Writer writer, Random rand,
    List<KeyValue> keyValues) throws IOException {

    for (int i = 0; i < entryCount; ++i) {
      byte[] keyBytes = RandomKeyValueUtil.randomOrderedKey(rand, i);

      // A random-length random value.
      byte[] valueBytes = RandomKeyValueUtil.randomValue(rand);
      KeyValue keyValue = null;
      if (useTags) {
        ArrayList<Tag> tags = new ArrayList<>();
        for (int j = 0; j < 1 + rand.nextInt(4); j++) {
          byte[] tagBytes = new byte[16];
          rand.nextBytes(tagBytes);
          tags.add(new ArrayBackedTag((byte) 1, tagBytes));
        }
        keyValue =
          new KeyValue(keyBytes, null, null, HConstants.LATEST_TIMESTAMP, valueBytes, tags);
      } else {
        keyValue = new KeyValue(keyBytes, null, null, HConstants.LATEST_TIMESTAMP, valueBytes);
      }
      writer.append(keyValue);
      keyValues.add(keyValue);
    }

    // Add in an arbitrary order. They will be sorted lexicographically by
    // the key.
    writer.appendMetaBlock("CAPITAL_OF_USA", new Text("Washington, D.C."));
    writer.appendMetaBlock("CAPITAL_OF_RUSSIA", new Text("Moscow"));
    writer.appendMetaBlock("CAPITAL_OF_FRANCE", new Text("Paris"));

    writer.close();
  }
Testing writing a version 3 {@link HFile} for all encoded blocks
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3WithDataEncoders.java