Java URI Value Check isFileSystemAvailable(File file, URI topLevelResource)

Here you can find the source of isFileSystemAvailable(File file, URI topLevelResource)

Description

Determines via best effort if the file system on which the file resides is available.

License

Open Source License

Parameter

Parameter Description
file a file
topLevelResource the top-level resource URI for the file.

Return

true if the file system is available, false otherwise.

Declaration

static boolean isFileSystemAvailable(File file, URI topLevelResource) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.net.URI;

public class Main {
    /**// w ww. j a  v a  2s .co m
     * Determines via best effort if the file system on which the file resides is available.
     * @param file a file
     * @param topLevelResource the top-level resource URI for the file.
     * @return true if the file system is available, false otherwise.
     */
    static boolean isFileSystemAvailable(File file, URI topLevelResource) {

        File topLevel = new File(topLevelResource);

        if (isEqualPath(file, topLevel)) {
            return file.exists();
        }

        return isFileSystemAvailable(file, topLevel);
    }

    private static boolean isFileSystemAvailable(File file,
            File topLevelResource) {

        boolean available;

        if (file.exists()) {
            available = true;
        } else {
            if (isEqualPath(file, topLevelResource)) {
                available = false;
            } else {
                available = isFileSystemAvailable(file.getParentFile(),
                        topLevelResource);
            }
        }

        return available;
    }

    private static boolean isEqualPath(File file1, File file2) {
        return file1.getAbsolutePath().equals(file2.getAbsolutePath());
    }
}

Related

  1. isExtensionUri(final URI uri)
  2. isFile(final URI uri)
  3. isFile(final URI uri)
  4. isFile(URI uri)
  5. isFile(URI uri)
  6. isFileUri(String uri)
  7. isFileURI(URI uri)
  8. isFileUri(URI uri)
  9. isFileURI(URI uri)