本文整理匯總了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");
}