public class DefaultFileSystemManager extends Object implements FileSystemManager
Constructor and Description |
---|
DefaultFileSystemManager() |
Modifier and Type | Method and Description |
---|---|
void |
_closeFileSystem(FileSystem fileSystem)
Closes the given file system.
|
void |
addExtensionMap(String extension,
String scheme)
Adds an file name extension mapping.
|
void |
addMimeTypeMap(String mimeType,
String scheme)
Adds a mime type mapping.
|
void |
addOperationProvider(String[] schemes,
FileOperationProvider operationProvider) |
void |
addOperationProvider(String scheme,
FileOperationProvider operationProvider)
Adds the specified FileOperationProvider for the specified scheme.
|
void |
addProvider(String[] urlSchemes,
FileProvider provider)
Registers a file system provider.
|
void |
addProvider(String urlScheme,
FileProvider provider)
Registers a file system provider.
|
protected void |
addVirtualFileSystemScheme(String rootUri) |
boolean |
canCreateFileSystem(FileObject file)
Determines if a layered file system can be created for a given file.
|
void |
close()
Closes the manager.
|
void |
closeFileSystem(FileSystem fileSystem)
Closes the given file system.
|
FileObject |
createFileSystem(FileObject file)
Creates a layered file system.
|
FileObject |
createFileSystem(String scheme,
FileObject file)
Creates a layered file system.
|
FileObject |
createVirtualFileSystem(FileObject rootFile)
Creates a virtual file system.
|
FileObject |
createVirtualFileSystem(String rootUri)
Creates an empty virtual file system.
|
void |
freeUnusedResources()
Free all resources used by unused file systems created by this manager.
|
FileObject |
getBaseFile()
Returns the base file used to resolve relative URI.
|
CacheStrategy |
getCacheStrategy()
Get the cache strategy used.
|
FileContentInfoFactory |
getFileContentInfoFactory()
get the fileContentInfoFactory used to determine the infos of a file content.
|
Class<?> |
getFileObjectDecorator()
Get the file object decorator used.
|
Constructor<?> |
getFileObjectDecoratorConst()
The constructor associated to the fileObjectDecorator.
|
FilesCache |
getFilesCache()
Returns the filesCache implementation used to cache files.
|
FileSystemConfigBuilder |
getFileSystemConfigBuilder(String scheme)
Get the configuration builder for the given scheme.
|
protected org.apache.commons.logging.Log |
getLogger()
Returns the logger used by this manager.
|
FileOperationProvider[] |
getOperationProviders(String scheme)
Gets Providers for file operations.
|
Collection<Capability> |
getProviderCapabilities(String scheme)
Get the capabilities for a given scheme.
|
FileReplicator |
getReplicator()
Returns the file replicator.
|
String[] |
getSchemes()
Get the schemes currently available.
|
TemporaryFileStore |
getTemporaryFileStore()
Returns the temporary file store.
|
URLStreamHandlerFactory |
getURLStreamHandlerFactory()
Get the URLStreamHandlerFactory.
|
boolean |
hasProvider(String scheme)
Returns true if this manager has a provider for a particular scheme.
|
void |
init()
Initializes this manager.
|
void |
removeProvider(String urlScheme)
Unregisters a file system provider.
|
FileObject |
resolveFile(FileObject baseFile,
String uri)
Resolves a URI, relative to a base file.
|
FileObject |
resolveFile(FileObject baseFile,
String uri,
FileSystemOptions fileSystemOptions)
Resolves a URI, relative to a base file with specified FileSystem configuration.
|
FileObject |
resolveFile(File baseFile,
String uri)
Resolves a URI, relative to base file.
|
FileObject |
resolveFile(String uri)
Locates a file by URI.
|
FileObject |
resolveFile(String uri,
FileSystemOptions fileSystemOptions)
Locate a file by URI, use the FileSystemOptions for file-system creation.
|
FileObject |
resolveFile(URI uri)
Converts a URI into a
FileObject . |
FileObject |
resolveFile(URL url)
Converts a URL into a
FileObject . |
FileName |
resolveName(FileName root,
String path)
Resolves a name, relative to the file.
|
FileName |
resolveName(FileName base,
String name,
NameScope scope)
Resolves a name, relative to the root.
|
FileName |
resolveURI(String uri)
Resolve the uri to a file name.
|
void |
setBaseFile(File baseFile)
Sets the base file to use when resolving relative URI.
|
void |
setBaseFile(FileObject baseFile)
Sets the base file to use when resolving relative URI.
|
void |
setCacheStrategy(CacheStrategy fileCacheStrategy)
Set the cache strategy to use when dealing with file object data.
|
void |
setDefaultProvider(FileProvider provider)
Sets the default provider.
|
void |
setFileContentInfoFactory(FileContentInfoFactory fileContentInfoFactory)
set the fileContentInfoFactory used to determine the infos of a file content.
|
void |
setFileObjectDecorator(Class<?> fileObjectDecorator)
Set a fileObject decorator to be used for ALL returned file objects.
|
void |
setFilesCache(FilesCache filesCache)
Sets the filesCache implementation used to cache files.
|
void |
setLogger(org.apache.commons.logging.Log log)
Sets the logger to use.
|
void |
setReplicator(FileReplicator replicator)
Sets the file replicator to use.
|
void |
setTemporaryFileStore(TemporaryFileStore tempFileStore)
Sets the temporary file store to use.
|
FileObject |
toFileObject(File file)
Converts a local file into a
FileObject . |
public void _closeFileSystem(FileSystem fileSystem)
If you use VFS as singleton it is VERY dangerous to call this method
fileSystem
- The FileSystem to close.public void addExtensionMap(String extension, String scheme)
extension
- The file name extension.scheme
- The scheme to use for files with this extension.public void addMimeTypeMap(String mimeType, String scheme)
mimeType
- The mime type.scheme
- The scheme to use for files with this mime type.public void addOperationProvider(String scheme, FileOperationProvider operationProvider) throws FileSystemException
addOperationProvider
in interface FileSystemManager
scheme
- The scheme the provider should be registered for.operationProvider
- The FileOperationProvider.FileSystemException
- if an error occurs adding the provider.public void addOperationProvider(String[] schemes, FileOperationProvider operationProvider) throws FileSystemException
addOperationProvider
in interface FileSystemManager
schemes
- The array of schemes the provider should apply to.operationProvider
- The FileOperationProvider.FileSystemException
- if an error occurs.FileSystemManager.addOperationProvider(String, org.apache.commons.vfs2.operations.FileOperationProvider)
public void addProvider(String urlScheme, FileProvider provider) throws FileSystemException
The manager takes care of all lifecycle management. A provider may be registered multiple times. The first
LocalFileProvider
added will be remembered for getLocalFileProvider()
.
urlScheme
- The scheme the provider will handle.provider
- The provider.FileSystemException
- if an error occurs adding the provider.public void addProvider(String[] urlSchemes, FileProvider provider) throws FileSystemException
The manager takes care of all lifecycle management. A provider may be registered multiple times. The first
LocalFileProvider
added will be remembered for getLocalFileProvider()
.
urlSchemes
- The schemes the provider will handle.provider
- The provider.FileSystemException
- if an error occurs adding the provider.protected void addVirtualFileSystemScheme(String rootUri)
public boolean canCreateFileSystem(FileObject file) throws FileSystemException
canCreateFileSystem
in interface FileSystemManager
file
- The file to check for.FileSystemException
- if an error occurs.public void close()
This will close all providers (all files), it will also close all managed components including temporary files, replicator, file cache and file operations.
The manager is in uninitialized state after this method.
close
in interface AutoCloseable
close
in interface FileSystemManager
public void closeFileSystem(FileSystem fileSystem)
If you use VFS as singleton it is VERY dangerous to call this method.
closeFileSystem
in interface FileSystemManager
fileSystem
- The FileSystem to close.public FileObject createFileSystem(FileObject file) throws FileSystemException
createFileSystem
in interface FileSystemManager
file
- The FileObject to use.FileSystemException
- if an error occurs.public FileObject createFileSystem(String scheme, FileObject file) throws FileSystemException
createFileSystem
in interface FileSystemManager
scheme
- The scheme to use.file
- The FileObject.FileSystemException
- if an error occurs.public FileObject createVirtualFileSystem(FileObject rootFile) throws FileSystemException
createVirtualFileSystem
in interface FileSystemManager
rootFile
- The FileObject to use.FileSystemException
- if an error occurs creating the file.public FileObject createVirtualFileSystem(String rootUri) throws FileSystemException
createVirtualFileSystem
in interface FileSystemManager
rootUri
- The URI to use as the root of the FileSystem.FileSystemException
- if an error occurs.public void freeUnusedResources()
public FileObject getBaseFile() throws FileSystemException
getBaseFile
in interface FileSystemManager
FileSystemException
- if an error occurs.public CacheStrategy getCacheStrategy()
getCacheStrategy
in interface FileSystemManager
public FileContentInfoFactory getFileContentInfoFactory()
getFileContentInfoFactory
in interface FileSystemManager
public Class<?> getFileObjectDecorator()
getFileObjectDecorator
in interface FileSystemManager
public Constructor<?> getFileObjectDecoratorConst()
getFileObjectDecoratorConst
in interface FileSystemManager
public FilesCache getFilesCache()
getFilesCache
in interface FileSystemManager
public FileSystemConfigBuilder getFileSystemConfigBuilder(String scheme) throws FileSystemException
getFileSystemConfigBuilder
in interface FileSystemManager
scheme
- The scheme to locate.FileSystemException
- if the given scheme is not konwnprotected org.apache.commons.logging.Log getLogger()
public FileOperationProvider[] getOperationProviders(String scheme) throws FileSystemException
FileSystemManager
getOperationProviders
in interface FileSystemManager
scheme
- the scheme for wich we want to get the list af registered providers.FileSystemException
- if an error occurs.public Collection<Capability> getProviderCapabilities(String scheme) throws FileSystemException
getProviderCapabilities
in interface FileSystemManager
scheme
- The scheme to located.FileSystemException
- if the given scheme is not konwnpublic FileReplicator getReplicator() throws FileSystemException
FileSystemException
- if there is no FileReplicator.public String[] getSchemes()
getSchemes
in interface FileSystemManager
public TemporaryFileStore getTemporaryFileStore() throws FileSystemException
FileSystemException
- if there is no TemporaryFileStore.public URLStreamHandlerFactory getURLStreamHandlerFactory()
getURLStreamHandlerFactory
in interface FileSystemManager
public boolean hasProvider(String scheme)
hasProvider
in interface FileSystemManager
scheme
- The scheme to check.public void init() throws FileSystemException
If no value for the following properties was specified, it will use the following defaults:
FileSystemException
- if an error occurs during initialization.public void removeProvider(String urlScheme)
urlScheme
- The scheme of the provider.public FileObject resolveFile(File baseFile, String uri) throws FileSystemException
Uses the local file provider to locate the system file.
resolveFile
in interface FileSystemManager
baseFile
- The base File to use to locate the file.uri
- The URI of the file to locate.FileSystemException
- if the file cannot be located or an error occurs.public FileObject resolveFile(FileObject baseFile, String uri) throws FileSystemException
resolveFile
in interface FileSystemManager
baseFile
- The base FileOjbect to use to locate the file.uri
- The URI of the file to locate.FileSystemException
- if the file cannot be located or an error occurs.public FileObject resolveFile(FileObject baseFile, String uri, FileSystemOptions fileSystemOptions) throws FileSystemException
baseFile
- The base file.uri
- The file name. May be a fully qualified or relative path or a url.fileSystemOptions
- Options to pass to the file system.FileSystemException
- if an error occurs accessing the file.public FileObject resolveFile(String uri) throws FileSystemException
resolveFile
in interface FileSystemManager
uri
- The URI of the file to locate.FileSystemException
- if the file cannot be located or an error occurs.public FileObject resolveFile(String uri, FileSystemOptions fileSystemOptions) throws FileSystemException
resolveFile
in interface FileSystemManager
uri
- The URI of the file to locate.fileSystemOptions
- The options for the FileSystem.FileSystemException
- if the file cannot be located or an error occurs.public FileObject resolveFile(URI uri) throws FileSystemException
FileObject
.resolveFile
in interface FileSystemManager
uri
- The URI to convert.FileObject
that represents the URI. Never returns null.FileSystemException
- On error converting the URI.public FileObject resolveFile(URL url) throws FileSystemException
FileObject
.resolveFile
in interface FileSystemManager
url
- The URL to convert.FileObject
that represents the URL. Never returns null.FileSystemException
- On error converting the URL.public FileName resolveName(FileName root, String path) throws FileSystemException
resolveName
in interface FileSystemManager
root
- The base FileName.path
- The path to the file relative to the base FileName or an absolute path.FileSystemException
- if an error occurs constructing the FileName.public FileName resolveName(FileName base, String name, NameScope scope) throws FileSystemException
resolveName
in interface FileSystemManager
base
- the base file namename
- the namescope
- the NameScope
FileSystemException
- if an error occurs.public FileName resolveURI(String uri) throws FileSystemException
resolveURI
in interface FileSystemManager
uri
- The URI to resolve.FileSystemException
- if an error occurs.public void setBaseFile(File baseFile) throws FileSystemException
baseFile
- The new base FileObject.FileSystemException
- if an error occurs.public void setBaseFile(FileObject baseFile)
baseFile
- The new base FileObject.public void setCacheStrategy(CacheStrategy fileCacheStrategy) throws FileSystemException
Can only be set before the FileSystemManager is initialized.
The default is CacheStrategy.ON_RESOLVE
.
fileCacheStrategy
- The CacheStrategy to use.FileSystemException
- if this is not possible. e.g. it is already set.public void setDefaultProvider(FileProvider provider) throws FileSystemException
provider
- The FileProvider.FileSystemException
- if an error occurs setting the provider.public void setFileContentInfoFactory(FileContentInfoFactory fileContentInfoFactory) throws FileSystemException
Can only be set before the FileSystemManager is initialized.
fileContentInfoFactory
- The FileContentInfoFactory.FileSystemException
- if an error occurs setting the FileContentInfoFactory.public void setFileObjectDecorator(Class<?> fileObjectDecorator) throws FileSystemException
Can only be set before the FileSystemManager is initialized.
fileObjectDecorator
- must be inherted from DecoratedFileObject
a has to provide a constructor with
a single FileObject
as argumentFileSystemException
- if an error occurs setting the decorator.public void setFilesCache(FilesCache filesCache) throws FileSystemException
Can only be set before the FileSystemManager is initialized.
The manager takes care of the lifecycle. If none is set, a default is picked in init()
.
filesCache
- The FilesCache.FileSystemException
- if an error occurs setting the cache..public void setLogger(org.apache.commons.logging.Log log)
This overwrites the default logger for this manager and is not reset in close()
.
setLogger
in interface FileSystemManager
log
- The Logger to use.public void setReplicator(FileReplicator replicator) throws FileSystemException
The manager takes care of all lifecycle management.
replicator
- The FileReplicator.FileSystemException
- if an error occurs setting the replicator.public void setTemporaryFileStore(TemporaryFileStore tempFileStore) throws FileSystemException
The manager takes care of all lifecycle management.
tempFileStore
- The temporary FileStore.FileSystemException
- if an error occurs adding the file store.public FileObject toFileObject(File file) throws FileSystemException
FileObject
.toFileObject
in interface FileSystemManager
file
- The input File.FileSystemException
- if an error occurs creating the file.Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.