private void serializeVersion0Tokens(List<RemoteReplicaInfo.ReplicaTokenInfo> tokenInfoList,
      FileOutputStream outputStream) throws IOException {
    CrcOutputStream crcOutputStream = new CrcOutputStream(outputStream);
    DataOutputStream writer = new DataOutputStream(crcOutputStream);
    try {
      // write the current version
      writer.writeShort(0);
      for (RemoteReplicaInfo.ReplicaTokenInfo replicaTokenInfo : tokenInfoList) {
        writer.write(replicaTokenInfo.getPartitionId().getBytes());
        // Write hostname
        writer.writeInt(replicaTokenInfo.getHostname().getBytes().length);
        writer.write(replicaTokenInfo.getHostname().getBytes());
        // Write replica path
        writer.writeInt(replicaTokenInfo.getReplicaPath().getBytes().length);
        writer.write(replicaTokenInfo.getReplicaPath().getBytes());
        // Write port
        writer.writeInt(replicaTokenInfo.getPort());
        //Write total bytes read from local store
        writer.writeLong(replicaTokenInfo.getTotalBytesReadFromLocalStore());
        // Write replica token
        writer.write(replicaTokenInfo.getReplicaToken().toBytes());
      }
      long crcValue = crcOutputStream.getValue();
      writer.writeLong(crcValue);
    } finally {
      if (outputStream != null) {
        // flush and overwrite file
        outputStream.getChannel().force(true);
      }
    }
  }
Serialize token in VERSION_0 format.
@param tokenInfoList {@link RemoteReplicaInfo.ReplicaTokenInfo} list to serialize.
@param outputStream {@link FileOutputStream} to persist the tokens to.
@throws IOException if an exception happens during serialization.
ambry-replication/src/test/java/com/github/ambry/replication/DiskTokenPersistorTest.java