mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8218875: Add new FileSystems.newFileSystem methods
Reviewed-by: rriggs, alanb, clanger, dfuchs
This commit is contained in:
parent
2c35825433
commit
5a4cef05d6
10 changed files with 349 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -365,14 +365,13 @@ public final class FileSystems {
|
|||
* systems where the contents of one or more files is treated as a file
|
||||
* system.
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers. It invokes, in turn, each provider's {@link
|
||||
* FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)} method
|
||||
* with an empty map. If a provider returns a file system then the iteration
|
||||
* terminates and the file system is returned. If none of the installed
|
||||
* providers return a {@code FileSystem} then an attempt is made to locate
|
||||
* the provider using the given class loader. If a provider returns a file
|
||||
* system then the lookup terminates and the file system is returned.
|
||||
* <p> This method first attempts to locate an installed provider in exactly
|
||||
* the same manner as the {@link #newFileSystem(Path, Map, ClassLoader)
|
||||
* newFileSystem(Path, Map, ClassLoader)} method with an empty map. If none
|
||||
* of the installed providers return a {@code FileSystem} then an attempt is
|
||||
* made to locate the provider using the given class loader. If a provider
|
||||
* returns a file system then the lookup terminates and the file system is
|
||||
* returned.
|
||||
*
|
||||
* @param path
|
||||
* the path to the file
|
||||
|
@ -395,11 +394,132 @@ public final class FileSystems {
|
|||
public static FileSystem newFileSystem(Path path,
|
||||
ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
return newFileSystem(path, Map.of(), loader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FileSystem} to access the contents of a file as a
|
||||
* file system.
|
||||
*
|
||||
* <p> This method makes use of specialized providers that create pseudo file
|
||||
* systems where the contents of one or more files is treated as a file
|
||||
* system.
|
||||
*
|
||||
* <p> This method first attempts to locate an installed provider in exactly
|
||||
* the same manner as the {@link #newFileSystem(Path,Map,ClassLoader)
|
||||
* newFileSystem(Path, Map, ClassLoader)} method. If found, the provider's
|
||||
* {@link FileSystemProvider#newFileSystem(Path, Map) newFileSystem(Path, Map)}
|
||||
* method is invoked to construct the new file system.
|
||||
*
|
||||
* @param path
|
||||
* the path to the file
|
||||
* @param env
|
||||
* a map of provider specific properties to configure the file system;
|
||||
* may be empty
|
||||
*
|
||||
* @return a new file system
|
||||
*
|
||||
* @throws ProviderNotFoundException
|
||||
* if a provider supporting this file type cannot be located
|
||||
* @throws ServiceConfigurationError
|
||||
* when an error occurs while loading a service provider
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission
|
||||
*
|
||||
* @since 13
|
||||
*/
|
||||
public static FileSystem newFileSystem(Path path, Map<String,?> env)
|
||||
throws IOException
|
||||
{
|
||||
return newFileSystem(path, env, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FileSystem} to access the contents of a file as a
|
||||
* file system.
|
||||
*
|
||||
* <p> This method makes use of specialized providers that create pseudo file
|
||||
* systems where the contents of one or more files is treated as a file
|
||||
* system.
|
||||
*
|
||||
* <p> This method first attempts to locate an installed provider in exactly
|
||||
* the same manner as the {@link #newFileSystem(Path,Map,ClassLoader)
|
||||
* newFileSystem(Path, Map, ClassLoader)} method. If found, the provider's
|
||||
* {@link FileSystemProvider#newFileSystem(Path, Map) newFileSystem(Path, Map)}
|
||||
* method is invoked with an empty map to construct the new file system.
|
||||
*
|
||||
* @param path
|
||||
* the path to the file
|
||||
*
|
||||
* @return a new file system
|
||||
*
|
||||
* @throws ProviderNotFoundException
|
||||
* if a provider supporting this file type cannot be located
|
||||
* @throws ServiceConfigurationError
|
||||
* when an error occurs while loading a service provider
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission
|
||||
*
|
||||
* @since 13
|
||||
*/
|
||||
public static FileSystem newFileSystem(Path path) throws IOException {
|
||||
return newFileSystem(path, Map.of(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code FileSystem} to access the contents of a file as a
|
||||
* file system.
|
||||
*
|
||||
* <p> This method makes use of specialized providers that create pseudo file
|
||||
* systems where the contents of one or more files is treated as a file
|
||||
* system.
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers. It invokes, in turn, each provider's {@link
|
||||
* FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)}
|
||||
* method. If a provider returns a file system then the iteration
|
||||
* terminates and the file system is returned.
|
||||
* If none of the installed providers return a {@code FileSystem} then
|
||||
* an attempt is made to locate the provider using the given class loader.
|
||||
* If a provider returns a file
|
||||
* system, then the lookup terminates and the file system is returned.
|
||||
*
|
||||
* @param path
|
||||
* the path to the file
|
||||
* @param env
|
||||
* a map of provider specific properties to configure the file system;
|
||||
* may be empty
|
||||
* @param loader
|
||||
* the class loader to locate the provider or {@code null} to only
|
||||
* attempt to locate an installed provider
|
||||
*
|
||||
* @return a new file system
|
||||
*
|
||||
* @throws ProviderNotFoundException
|
||||
* if a provider supporting this file type cannot be located
|
||||
* @throws ServiceConfigurationError
|
||||
* when an error occurs while loading a service provider
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission
|
||||
*
|
||||
* @since 13
|
||||
*/
|
||||
public static FileSystem newFileSystem(Path path, Map<String,?> env,
|
||||
ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
if (path == null)
|
||||
throw new NullPointerException();
|
||||
Map<String,?> env = Collections.emptyMap();
|
||||
|
||||
// check installed providers
|
||||
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue