本文整理汇总了Java中java.nio.file.spi.FileSystemProvider.getFileSystem方法的典型用法代码示例。如果您正苦于以下问题:Java FileSystemProvider.getFileSystem方法的具体用法?Java FileSystemProvider.getFileSystem怎么用?Java FileSystemProvider.getFileSystem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.spi.FileSystemProvider
的用法示例。
在下文中一共展示了FileSystemProvider.getFileSystem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileSystem
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
/**
* Retrieves a file system using the default {@link FileSystems#getFileSystem(URI)}. If this
* throws a
* @param uri
* @return
*/
public static FileSystem getFileSystem(URI uri) {
try {
return FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException | ProviderNotFoundException e) {
LOG.debug("File system scheme " + uri.getScheme() +
" not found in the default installed providers list, attempting to find this in the "
+ "list of additional providers");
}
for (WeakReference<FileSystemProvider> providerRef : providers) {
FileSystemProvider provider = providerRef.get();
if (provider != null && uri.getScheme().equals(provider.getScheme())) {
return provider.getFileSystem(uri);
}
}
throw new ProviderNotFoundException("Could not find provider for scheme '" + uri.getScheme() + "'");
}
示例2: getInstance
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
/**
* Returns any subclass that implements and handles the given scheme.
* @param scheme a valid {@link URI} scheme
* @see FileSystemProvider#getScheme()
* @throws FileSystemNotFoundException if no filesystem handles this scheme
*/
public static MCRAbstractFileSystem getInstance(String scheme) {
URI uri;
try {
uri = MCRPaths.getURI(scheme, "helper", SEPARATOR_STRING);
} catch (URISyntaxException e) {
throw new MCRException(e);
}
for (FileSystemProvider provider : Iterables.concat(MCRPaths.webAppProvider,
FileSystemProvider.installedProviders())) {
if (provider.getScheme().equals(scheme)) {
return (MCRAbstractFileSystem) provider.getFileSystem(uri);
}
}
throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not found");
}
示例3: defaultFileSystem
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
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:///"));
}
示例4: defaultFileSystem
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
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:///"));
}
示例5: zipFileSystem
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
public static FileSystem zipFileSystem( URI fileJarURI ) {
final Map<String, Object> env = Maps.map( "create", ( Object ) "true" );
FileSystemProvider provider = loadFileSystemProvider("jar");
Exceptions.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,
Str.sputs("unable to load", fileJarURI, "as zip file system"),
ex2 );
}
}
}
Exceptions.requireNonNull(provider, "Zip file system was not found");
return fs;
}
示例6: TestProvider
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
public TestProvider(FileSystemProvider defaultProvider) {
this.defaultProvider = defaultProvider;
FileSystem fs = defaultProvider.getFileSystem(URI.create("file:/"));
this.theFileSystem = new TestFileSystem(fs, this);
}
示例7: getFileSystem
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
/**
* 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");
}
示例8: getFileSystem
import java.nio.file.spi.FileSystemProvider; //导入方法依赖的package包/类
/**
* 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.
*
* @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");
}