@SuppressWarnings("deprecation")
    private void printReply(Reply reply) {
        Trace trace = reply.getTrace();
        if (!trace.getRoot().isEmpty()) {
            System.out.println(trace);
        }

        if (reply.hasErrors()) {
            System.err.print("Request failed: ");
            for (int i = 0; i < reply.getNumErrors(); i++) {
                System.err.printf("\n  %s", reply.getError(i));
            }
            System.err.println();
            return;
        }

        if (!(reply instanceof GetDocumentReply)) {
            System.err.printf("Unexpected reply %s: '%s'\n", reply.getType(), reply.toString());
            return;
        }

        GetDocumentReply documentReply = (GetDocumentReply) reply;
        Document document = documentReply.getDocument();

        if (document == null) {
            System.out.println("Document not found.");
            return;
        }

        if (params.showDocSize) {
            System.out.printf("Document size: %d bytes.\n", document.getSerializedSize());
        }
        if (params.printIdsOnly) {
            System.out.println(document.getId());
        } else {
            if (params.jsonOutput) {
                System.out.print(Utf8.toString(JsonWriter.toByteArray(document, params.tensorShortForm, params.tensorDirectValues)));
            } else {
                System.out.print(document.toXML("  "));
            }
        }
    }
The document retriever is responsible for retrieving documents using the Document API and printing the result to standard out.

@author bjorncs
vespaclient-java/src/main/java/com/yahoo/vespaget/DocumentRetriever.java