Java File System isFileSystemAvailable(final Path file, final String topLevelAbsolutePath)

Here you can find the source of isFileSystemAvailable(final Path file, final String topLevelAbsolutePath)

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
topLevelAbsolutePath the top-level resource URI for the file.

Return

true if the file system is available, false otherwise.

Declaration

static boolean isFileSystemAvailable(final Path file,
        final String topLevelAbsolutePath) 

Method Source Code

//package com.java2s;

import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    /**//from   www  .  ja  v  a 2 s. c o  m
     * Determines via best effort if the file system on which the file resides is available.
     * @param file a file
     * @param topLevelAbsolutePath  the top-level resource URI for the file.
     * @return true if the file system is available, false otherwise.
     */
    static boolean isFileSystemAvailable(final Path file,
            final String topLevelAbsolutePath) {
        if (isEqualPath(file, topLevelAbsolutePath)) {
            return Files.exists(file);
        }

        return isFileSystemAvailable2(file, topLevelAbsolutePath);
    }

    private static boolean isEqualPath(final Path file1,
            final String topLevelAbsolutePath) {
        return topLevelAbsolutePath.equals(file1.toAbsolutePath()
                .toString());
    }

    private static boolean isFileSystemAvailable2(final Path file,
            final String topLevelAbsolutePath) {

        boolean available;

        if (Files.exists(file)) {
            available = true;
        } else {
            if (isEqualPath(file, topLevelAbsolutePath)) {
                available = false;
            } else {
                available = isFileSystemAvailable2(file.getParent(),
                        topLevelAbsolutePath);
            }
        }

        return available;
    }
}

Related

  1. findFile(FileSystem fileSystem, String path, String optionalFileSuffix)
  2. getFileSystem(Path file)
  3. getFileSystem(Path path)
  4. getPath(FileSystem targetFS, String fileName)
  5. isFileSystemAvailable2(final Path file, final String topLevelAbsolutePath)
  6. loadSystemResourceKeyValueCsvFileToMap(String resourcePath)
  7. newJarFileSystem(Path jarFilePath)
  8. newOutputStream(FileSystem system, Path path)