public Optional<DocumentParseInfo> parse(Optional<DocumentId> documentIdArg) throws IOException {
        indentLevel = 0;
        DocumentParseInfo documentParseInfo = new DocumentParseInfo();
        documentIdArg.ifPresent(documentId -> documentParseInfo.documentId = documentId);
        boolean foundItems = false;
        do {
            foundItems |= parseOneItem(documentParseInfo, documentIdArg.isPresent() /* doc id set externally */);
        } while (indentLevel > 0L);

        if (documentParseInfo.documentId == null) {
            if (foundItems)
                throw new IllegalArgumentException("Missing a document operation ('put', 'update' or 'remove')");
            else
                return Optional.empty();
        }
        return Optional.of(documentParseInfo);
    }
Parses a single document and returns it.
Returns empty if we have reached the end of the stream.
document/src/main/java/com/yahoo/document/json/document/DocumentParser.java