private boolean isValidDirectoryUri(final Uri dirUri, final boolean needsWrite) throws IOException {
        try {
            return queryDoc(dirUri, new String[]{DocumentsContract.Document.COLUMN_MIME_TYPE, DocumentsContract.Document.COLUMN_FLAGS}, false, c ->
                    DocumentsContract.Document.MIME_TYPE_DIR.equals(c.getString(0)) &&
                            (!needsWrite || (c.getInt(1) & DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE) != 0));
        } catch (IllegalArgumentException iae) {
            //this is thrown if dirUri does not exist
            Log.d("Exception in isValidDirectoryUri for uri '" + dirUri + "', nw=" + needsWrite);
            return false;
        }
    }
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