code: public static void writeLeaves(DataOutput out, MerkleTreeView merkleTreeView) throws IOException {
          int leafLevel = merkleTreeView.depth() - 1;
          int numberOfLeaves = getNodesOnLevel(leafLevel);
          int leftMostLeaf = getLeftMostNodeOrderOnLevel(leafLevel);
  
          out.writeInt(numberOfLeaves);
  
          for (int leafOrder = leftMostLeaf; leafOrder < leftMostLeaf + numberOfLeaves; leafOrder++) {
              out.writeInt(merkleTreeView.getNodeHash(leafOrder));
          }
      }
docs: Writes the hashes of the leaves of a Merkle tree into the
  provided {@link DataOutput}
  
  @param out            The data output to write the leaves into
  @param merkleTreeView The Merkle tree which leaves to be written
  into the data output
  @throws IOException if an I/O error occurs