Package org.apache.commons.vfs2
Interface FileSystemManager
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultFileSystemManager
,StandardFileSystemManager
A FileSystemManager manages a set of file systems. This interface is used to locate a
FileObject
by name from
one of those file systems.
To locate a FileObject
, use one of the resolveFile()
methods.
File Naming
A file system manager can recognize several types of file names:
- Absolute URI. These must start with a scheme, such as
file:
orftp:
, followed by a scheme dependent file name. Some examples:file:/c:/somefile
orftp://somewhere.org/somefile
. - Absolute local file name. For example,
/home/someuser/a-file
orc:\dir\somefile.html
. Elements in the name can be separated using any of the following characters:/
,\
, or the native file separator character. For example, the following file names are the same:c:\somedir\somefile.xml
andc:/somedir/somefile.xml
. - Relative path. For example:
../somefile
orsomedir/file.txt
. The file system manager resolves relative paths against its base file. Elements in the relative path can be separated using/
,\
, or file system specific separator characters. Relative paths may also contain..
and.
elements. SeeFileObject.resolveFile(java.lang.String)
for more details.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOperationProvider
(String[] schemes, FileOperationProvider operationProvider) Adds an operation provider.void
addOperationProvider
(String scheme, FileOperationProvider operationProvider) Adds the specified FileOperationProvider for the specified scheme.boolean
Determines if a layered file system can be created for a given file.default void
close()
Closes this file system manager.void
closeFileSystem
(FileSystem fileSystem) Closes the given file system.createFileSystem
(String provider, FileObject file) Creates a layered file system.createFileSystem
(FileObject file) Creates a layered file system.createVirtualFileSystem
(String rootUri) Creates an empty virtual file system.createVirtualFileSystem
(FileObject rootFile) Creates a virtual file system.Returns the base file used to resolve relative paths.Gets the cache strategy used.Gets the class to use to determine the content-type (mime-type).Class<?>
Gets the file object decorator used.Constructor<?>
Gets the constructor associated to the fileObjectDecorator.Gets the cache used to cache file objects.getFileSystemConfigBuilder
(String scheme) Gets the configuration builder for the given scheme.getOperationProviders
(String scheme) Gets Providers for file operations.getProviderCapabilities
(String scheme) Gets the capabilities for a given scheme.String[]
Gets the schemes currently available.Returns a stream handler factory to enable URL lookup using this FileSystemManager.boolean
hasProvider
(String scheme) Returns true if this manager has a provider for a particular scheme.resolveFile
(File baseFile, String name) Locates a file by name.resolveFile
(String name) Locates a file by name.resolveFile
(String name, FileSystemOptions fileSystemOptions) Locates a file by name.resolveFile
(URI uri) Resolves a URI into aFileObject
.resolveFile
(URL url) Resolves a URL into aFileObject
.resolveFile
(FileObject baseFile, String name) Locates a file by name.resolveName
(FileName root, String name) Resolves a name, relative to this file name.resolveName
(FileName root, String name, NameScope scope) Resolves a name, relative to the "root" file name.resolveURI
(String uri) Resolves the URI to a file name.void
setLogger
(org.apache.commons.logging.Log log) Sets the logger to use.toFileObject
(File file) Converts a local file into aFileObject
.default FileObject
toFileObject
(Path path) Converts a local path into aFileObject
.
-
Method Details
-
addOperationProvider
void addOperationProvider(String scheme, FileOperationProvider operationProvider) throws FileSystemException Adds the specified FileOperationProvider for the specified scheme.Several FileOperationProvider's might be registered for the same scheme. For example, for
"file"
scheme we can registerSvnWsOperationProvider
andCvsOperationProvider.
- Parameters:
scheme
- The scheme associated with this provider.operationProvider
- The FileOperationProvider to add.- Throws:
FileSystemException
- if an error occurs.
-
addOperationProvider
void addOperationProvider(String[] schemes, FileOperationProvider operationProvider) throws FileSystemException Adds an operation provider.- Parameters:
schemes
- The schemes that will be associated with the provider.operationProvider
- The FileOperationProvider to add.- Throws:
FileSystemException
- if an error occurs.- See Also:
-
canCreateFileSystem
Determines if a layered file system can be created for a given file.- Parameters:
file
- The file to check for.- Returns:
- true if the FileSystem can be created.
- Throws:
FileSystemException
- if an error occurs.
-
close
Closes this file system manager.- Specified by:
close
in interfaceAutoCloseable
- Since:
- 2.5.0
-
closeFileSystem
Closes the given file system.If you use VFS as singleton it is VERY dangerous to call this method.
- Parameters:
fileSystem
- The FileSystem to close.
-
createFileSystem
Creates a layered file system. A layered file system is a file system that is created from the contents of a file, such as a ZIP or tar file.- Parameters:
file
- The file to use to create the file system.- Returns:
- The root file of the new file system.
- Throws:
FileSystemException
- On error creating the file system.
-
createFileSystem
Creates a layered file system. A layered file system is a file system that is created from the contents of a file, such as a ZIP or tar file.- Parameters:
provider
- The name of the file system provider to use. This name is the same as the scheme used in URI to identify the provider.file
- The file to use to create the file system.- Returns:
- The root file of the new file system.
- Throws:
FileSystemException
- On error creating the file system.
-
createVirtualFileSystem
Creates a virtual file system. The file system will contain a junction at the fs root to the supplied root file.- Parameters:
rootFile
- The root file to backs the file system.- Returns:
- The root of the new file system.
- Throws:
FileSystemException
- if an error occurs creating the VirtualFileSystem.
-
createVirtualFileSystem
Creates an empty virtual file system. Can be populated by adding junctions to it.- Parameters:
rootUri
- The root URI to use for the new file system. Can be null.- Returns:
- The root file of the new file system.
- Throws:
FileSystemException
- if an error occurs creating the VirtualFileSystem.
-
getBaseFile
Returns the base file used to resolve relative paths.- Returns:
- The base FileObject.
- Throws:
FileSystemException
- if an error occurs.
-
getCacheStrategy
Gets the cache strategy used.- Returns:
- the CacheStrategy.
-
getFileContentInfoFactory
Gets the class to use to determine the content-type (mime-type).- Returns:
- the FileContentInfoFactory.
-
getFileObjectDecorator
Gets the file object decorator used.- Returns:
- the file object decorator Class.
-
getFileObjectDecoratorConst
Gets the constructor associated to the fileObjectDecorator. We cache it here for performance reasons.- Returns:
- the Constructor associated with the FileObjectDecorator.
-
getFilesCache
Gets the cache used to cache file objects.- Returns:
- The FilesCache.
-
getFileSystemConfigBuilder
Gets the configuration builder for the given scheme.- Parameters:
scheme
- The scheme to use to obtain the FileSystemConfigBuilder.- Returns:
- A FileSystemConfigBuilder appropriate for the given scheme.
- Throws:
FileSystemException
- if the given scheme is not known.
-
getOperationProviders
Gets Providers for file operations.- Parameters:
scheme
- the scheme for which we want to get the list af registered providers.- Returns:
- the registered FileOperationProviders for the specified scheme. If there were no providers registered for the scheme, it returns null.
- Throws:
FileSystemException
- if an error occurs.
-
getProviderCapabilities
Gets the capabilities for a given scheme.- Parameters:
scheme
- The scheme to use to locate the provider's capabilities.- Returns:
- A Collection of the various capabilities.
- Throws:
FileSystemException
- if the given scheme is not known.
-
getSchemes
String[] getSchemes()Gets the schemes currently available.- Returns:
- An array of available scheme names that are supported.
-
getURLStreamHandlerFactory
Returns a stream handler factory to enable URL lookup using this FileSystemManager.- Returns:
- the URLStreamHandlerFactory.
-
hasProvider
Returns true if this manager has a provider for a particular scheme.- Parameters:
scheme
- The scheme for which a provider should be checked.- Returns:
- true if a provider for the scheme is available.
-
resolveFile
Locates a file by name. SeeresolveFile(FileObject, String)
for details.- Parameters:
baseFile
- The base file to use to resolve relative paths. Must not benull
, not even if the name is absolute.name
- The name of the file.- Returns:
- The file. Never returns null.
- Throws:
FileSystemException
- On error parsing the file name.
-
resolveFile
Locates a file by name. The name is resolved as described above. That is, the name can be either an absolute URI, an absolute file name, or a relative path to be resolved againstbaseFile
.Note that the file does not have to exist when this method is called.
- Parameters:
baseFile
- The base file to use to resolve relative paths. May be null if the name is an absolute file name.name
- The name of the file.- Returns:
- The file. Never returns null.
- Throws:
FileSystemException
- On error parsing the file name.
-
resolveFile
Locates a file by name. Equivalent to callingresolveFile(getBaseFile(), name)
.- Parameters:
name
- The name of the file.- Returns:
- The file. Never returns null.
- Throws:
FileSystemException
- On error parsing the file name.
-
resolveFile
Locates a file by name. Equivalent to callingresolveFile(getBaseFile(), name)
.- Parameters:
name
- The name of the file.fileSystemOptions
- The FileSystemOptions used for FileSystem creation. All files that are later resolved relative to the returnedFileObject
share the options.- Returns:
- The file. Never returns null.
- Throws:
FileSystemException
- On error parsing the file name.
-
resolveFile
Resolves a URI into aFileObject
.- Parameters:
uri
- The URI to convert.- Returns:
- The
FileObject
that represents the URI. Never returns null. - Throws:
FileSystemException
- On error converting the file.- Since:
- 2.1
-
resolveFile
Resolves a URL into aFileObject
.- Parameters:
url
- The URL to convert.- Returns:
- The
FileObject
that represents the URL. Never returns null. - Throws:
FileSystemException
- On error converting the file.- Since:
- 2.1
-
resolveName
Resolves a name, relative to this file name. Equivalent to callingresolveName( path, NameScope.FILE_SYSTEM )
.- Parameters:
root
- the base file namename
- The name to resolve.- Returns:
- A
FileName
object representing the resolved file name. - Throws:
FileSystemException
- If the name is invalid.
-
resolveName
Resolves a name, relative to the "root" file name. Refer toNameScope
for a description of how names are resolved.- Parameters:
root
- the base file namename
- The name to resolve.scope
- TheNameScope
to use when resolving the name.- Returns:
- A
FileName
object representing the resolved file name. - Throws:
FileSystemException
- If the name is invalid.
-
resolveURI
Resolves the URI to a file name.- Parameters:
uri
- The URI to resolve.- Returns:
- A FileName that matches the URI.
- Throws:
FileSystemException
- if this is not possible.
-
setLogger
Sets the logger to use.- Parameters:
log
- The logger to use.
-
toFileObject
Converts a local file into aFileObject
.- Parameters:
file
- The file to convert.- Returns:
- The
FileObject
that represents the local file. Never returns null. - Throws:
FileSystemException
- On error converting the file.
-
toFileObject
Converts a local path into aFileObject
.- Parameters:
path
- The path to convert.- Returns:
- The
FileObject
that represents the local file. Never returns null. - Throws:
FileSystemException
- On error converting the file.- Since:
- 2.10.0
-