private Uri getFolderUri(final Folder folder, final boolean needsWrite, final boolean createIfNeeded, final boolean validateCache) throws IOException, IllegalArgumentException {
        if (folder == null) {
            return null;
        }

        try (ContextLogger cLog = new ContextLogger("DocumentFolderAccessor.getFolderUri: %s", folder)) {

            final Uri treeUri = folder.getBaseUri();
            if (!checkUriPermissions(treeUri, needsWrite)) {
                Log.d("Uri failed permission check: '" + treeUri + "', nw =" + needsWrite);
                return null;
            }
            final Uri baseUri = DocumentsContract.buildDocumentUriUsingTree(treeUri, DocumentsContract.getTreeDocumentId(treeUri));

            if (validateCache && !isValidDirectoryUri(baseUri, needsWrite)) {
                Log.d("Uri not a valid directory uri: '" + baseUri + "', nw =" + needsWrite);
                return null;
            }
            cLog.add("got base");

            return getSubdirUri(baseUri, folder.getSubdirsToBase(), needsWrite, createIfNeeded, validateCache);
        }
    }
Gets the Folder File; creates it if necessary and performs all possible error handlings.
This is used for locations of Type DOCUMENT and FILE
<br
This method is in many respects the core method of this class

@param folder folder to get file for
@return file folder, or null if creation/retrieving was not at all possible
main/src/main/java/cgeo/geocaching/storage/DocumentContentAccessor.java