Java Code Examples for java.nio.file.spi.FileSystemProvider#getFileSystem()

The following examples show how to use java.nio.file.spi.FileSystemProvider#getFileSystem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Module.java    From synthea with Apache License 2.0 7 votes vote down vote up
private static void fixPathFromJar(URI uri) throws IOException {
  // this function is a hack to enable reading modules from within a JAR file
  // see https://stackoverflow.com/a/48298758
  if ("jar".equals(uri.getScheme())) {
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
      if (provider.getScheme().equalsIgnoreCase("jar")) {
        try {
          provider.getFileSystem(uri);
        } catch (FileSystemNotFoundException e) {
          // in this case we need to initialize it first:
          provider.newFileSystem(uri, Collections.emptyMap());
        }
      }
    }
  }
}
 
Example 2
Source File: FileSystems.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 3
Source File: FileSystems.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 4
Source File: FileSystems.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 5
Source File: FileSystems.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 6
Source File: IO.java    From boon with Apache License 2.0 5 votes vote down vote up
public static FileSystem zipFileSystem( URI fileJarURI ) {



        final Map<String, Object> env = Maps.map( "create", ( Object ) "true" );

        FileSystemProvider provider = loadFileSystemProvider("jar");

        requireNonNull( provider, "Zip file provider not found" );

        FileSystem fs = null;

        try {
            fs = provider.getFileSystem( fileJarURI );
        } catch ( Exception ex ) {
            if ( provider != null ) {
                try {
                    fs = provider.newFileSystem( fileJarURI, env );
                } catch ( IOException ex2 ) {
                    Exceptions.handle( FileSystem.class,
                            sputs( "unable to load", fileJarURI, "as zip file system" ),
                            ex2 );
                }
            }
        }

        requireNonNull( provider, "Zip file system was not found" );

        return fs;
    }
 
Example 7
Source File: FileSystems.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 8
Source File: FileSystems.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 9
Source File: FileSystems.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 10
Source File: FileSystems.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static FileSystem defaultFileSystem() {
    // load default provider
    FileSystemProvider provider = AccessController
        .doPrivileged(new PrivilegedAction<FileSystemProvider>() {
            public FileSystemProvider run() {
                return getDefaultProvider();
            }
        });

    // return file system
    return provider.getFileSystem(URI.create("file:///"));
}
 
Example 11
Source File: TestProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public TestProvider(FileSystemProvider defaultProvider) {
    this.defaultProvider = defaultProvider;
    FileSystem fs = defaultProvider.getFileSystem(URI.create("file:/"));
    this.theFileSystem = new TestFileSystem(fs, this);
}
 
Example 12
Source File: FileSystems.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 13
Source File: FileSystems.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 14
Source File: FileSystems.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 15
Source File: FileSystems.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 16
Source File: FileSystems.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 17
Source File: FileSystems.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 18
Source File: FileSystems.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 19
Source File: FileSystems.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}
 
Example 20
Source File: FileSystems.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a reference to an existing {@code FileSystem}.
 *
 * <p> This method iterates over the {@link FileSystemProvider#installedProviders()
 * installed} providers to locate the provider that is identified by the URI
 * {@link URI#getScheme scheme} of the given URI. URI schemes are compared
 * without regard to case. The exact form of the URI is highly provider
 * dependent. If found, the provider's {@link FileSystemProvider#getFileSystem
 * getFileSystem} method is invoked to obtain a reference to the {@code
 * FileSystem}.
 *
 * <p> Once a file system created by this provider is {@link FileSystem#close
 * closed} it is provider-dependent if this method returns a reference to
 * the closed file system or throws {@link FileSystemNotFoundException}.
 * If the provider allows a new file system to be created with the same URI
 * as a file system it previously created then this method throws the
 * exception if invoked after the file system is closed (and before a new
 * instance is created by the {@link #newFileSystem newFileSystem} method).
 *
 * <p> If a security manager is installed then a provider implementation
 * may require to check a permission before returning a reference to an
 * existing file system. In the case of the {@link FileSystems#getDefault
 * default} file system, no permission check is required.
 *
 * @param   uri  the URI to locate the file system
 *
 * @return  the reference to the file system
 *
 * @throws  IllegalArgumentException
 *          if the pre-conditions for the {@code uri} parameter are not met
 * @throws  FileSystemNotFoundException
 *          if the file system, identified by the URI, does not exist
 * @throws  ProviderNotFoundException
 *          if a provider supporting the URI scheme is not installed
 * @throws  SecurityException
 *          if a security manager is installed and it denies an unspecified
 *          permission
 */
public static FileSystem getFileSystem(URI uri) {
    String scheme = uri.getScheme();
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
        if (scheme.equalsIgnoreCase(provider.getScheme())) {
            return provider.getFileSystem(uri);
        }
    }
    throw new ProviderNotFoundException("Provider \"" + scheme + "\" not found");
}