Use the RefDatabase#getRefs to walk through the existing refs:
RefDatabase refDatabase = repository.getRefDatabase();
Map<String, Ref> refs = refDatabase.getRefs(Constants.R_REMOTES);
for (Ref remoteRef : refs) {
// ...
}
The argument to getRefs is a prefix to get only certain refs, you can also use RefDatabase.ALL
for getting all refs.
For reading the file contents, walk the tree as in the code from the question. Then, with the TreeWalk object, the contents can be read. See this answer from the How to “cat” a file in JGit? question.