Class DefaultFileSystemManager
- All Implemented Interfaces:
AutoCloseable, FileSystemManager
- Direct Known Subclasses:
StandardFileSystemManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final classThis is an internal class because it needs access to the private member providers. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FileObjectThe base file to use for relative URI.All components used by this manager.private final DefaultVfsComponentContextThe context to pass to providers.private FileProviderThe default provider.private CacheStrategyThe cache strategyprivate FileContentInfoFactoryThe class to use to determine the content-type (mime-type)private Class<?> Class which decorates all returned fileObjectsprivate Constructor<?> Reflection constructor extracted fromfileObjectDecoratorprivate FileReplicatorThe file replicator to use.private FilesCacheThe files cacheprivate booleanFlag, if manager is initialized (after init() and before close()).private LocalFileProviderThe provider for local files.private org.apache.commons.logging.LogThe logger to use.private final Map<String, List<FileOperationProvider>> Operations providers added to this manager.private final Map<String, FileProvider> Mapping from URI scheme to FileProvider.private TemporaryFileStoreThe temporary file store to use.private final FileTypeMapMappings of file types.private VirtualFileProviderThe virtual file provider.List of the schemes of virtual file systems added. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid_closeFileSystem(FileSystem fileSystem) Closes the given file system.voidaddExtensionMap(String extension, String scheme) Adds an file name extension mapping.voidaddMimeTypeMap(String mimeType, String scheme) Adds a mime type mapping.voidaddOperationProvider(String[] schemes, FileOperationProvider operationProvider) voidaddOperationProvider(String scheme, FileOperationProvider operationProvider) Adds the specified FileOperationProvider for the specified scheme.voidaddProvider(String[] urlSchemes, FileProvider provider) Registers a file system provider.voidaddProvider(String urlScheme, FileProvider provider) Registers a file system provider.protected voidaddVirtualFileSystemScheme(String rootUri) booleanDetermines if a layered file system can be created for a given file.voidclose()Closes the manager.private voidcloseComponent(Object component) Closes a component, if it has not already been closed.voidcloseFileSystem(FileSystem fileSystem) Closes the given file system.createFileSystem(String scheme, 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.voidFree all resources used by unused file systems created by this manager.Returns the base file used to resolve relative URI.Get the cache strategy used.get the fileContentInfoFactory used to determine the infos of a file content.Class<?> Get the file object decorator used.Constructor<?> The constructor associated to the fileObjectDecorator.Returns the filesCache implementation used to cache files.getFileSystemConfigBuilder(String scheme) Get the configuration builder for the given scheme.private LocalFileProviderLocates the local file provider.protected org.apache.commons.logging.LogReturns the logger used by this manager.getOperationProviders(String scheme) Gets Providers for file operations.getProviderCapabilities(String scheme) Get the capabilities for a given scheme.Returns the file replicator.String[]Get the schemes currently available.Returns the temporary file store.Get the URLStreamHandlerFactory.booleanhasProvider(String scheme) Returns true if this manager has a provider for a particular scheme.voidinit()Initializes this manager.voidremoveProvider(String urlScheme) Unregisters a file system provider.resolveFile(File baseFile, String uri) Resolves a URI, relative to base file.resolveFile(String uri) Locates a file by URI.resolveFile(String uri, FileSystemOptions fileSystemOptions) Locate a file by URI, use the FileSystemOptions for file-system creation.resolveFile(URI uri) Converts a URI into aFileObject.resolveFile(URL url) Converts a URL into aFileObject.resolveFile(FileObject baseFile, String uri) Resolves a URI, relative to a base file.resolveFile(FileObject baseFile, String uri, FileSystemOptions fileSystemOptions) Resolves a URI, relative to a base file with specified FileSystem configuration.resolveName(FileName root, String path) Resolves a name, relative to the file.resolveName(FileName base, String name, NameScope scope) Resolves a name, relative to the root.resolveURI(String uri) Resolve the uri to a file name.voidsetBaseFile(File baseFile) Sets the base file to use when resolving relative URI.voidsetBaseFile(FileObject baseFile) Sets the base file to use when resolving relative URI.voidsetCacheStrategy(CacheStrategy fileCacheStrategy) Set the cache strategy to use when dealing with file object data.voidsetDefaultProvider(FileProvider provider) Sets the default provider.voidsetFileContentInfoFactory(FileContentInfoFactory fileContentInfoFactory) set the fileContentInfoFactory used to determine the infos of a file content.voidsetFileObjectDecorator(Class<?> fileObjectDecorator) Set a fileObject decorator to be used for ALL returned file objects.voidsetFilesCache(FilesCache filesCache) Sets the filesCache implementation used to cache files.voidsetLogger(org.apache.commons.logging.Log log) Sets the logger to use.voidsetReplicator(FileReplicator replicator) Sets the file replicator to use.voidsetTemporaryFileStore(TemporaryFileStore tempFileStore) Sets the temporary file store to use.private voidsetupComponent(Object component) Initializes a component, if it has not already been initialized.toFileObject(File file) Converts a local file into aFileObject.
-
Field Details
-
providers
Mapping from URI scheme to FileProvider. -
virtualFileSystemSchemes
-
components
-
context
The context to pass to providers. -
operationProviders
Operations providers added to this manager. -
typeMap
Mappings of file types. -
localFileProvider
The provider for local files. -
defaultProvider
The default provider. -
fileReplicator
The file replicator to use. -
baseFile
The base file to use for relative URI. -
filesCache
The files cache -
fileCacheStrategy
The cache strategy -
fileObjectDecorator
Class which decorates all returned fileObjects -
fileObjectDecoratorConst
Reflection constructor extracted fromfileObjectDecorator -
fileContentInfoFactory
The class to use to determine the content-type (mime-type) -
log
private org.apache.commons.logging.Log logThe logger to use. Default implementation. -
tempFileStore
The temporary file store to use. -
vfsProvider
The virtual file provider. -
init
private boolean initFlag, if manager is initialized (after init() and before close()).
-
-
Constructor Details
-
DefaultFileSystemManager
public DefaultFileSystemManager()
-
-
Method Details
-
_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.
-
addExtensionMap
-
addMimeTypeMap
-
addOperationProvider
public 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 register SvnWsOperationProvider and CvsOperationProvider.- Specified by:
addOperationProviderin interfaceFileSystemManager- Parameters:
scheme- The scheme the provider should be registered for.operationProvider- The FileOperationProvider.- Throws:
FileSystemException- if an error occurs adding the provider.
-
addOperationProvider
public void addOperationProvider(String[] schemes, FileOperationProvider operationProvider) throws FileSystemException - Specified by:
addOperationProviderin interfaceFileSystemManager- Parameters:
schemes- The array of schemes the provider should apply to.operationProvider- The FileOperationProvider.- Throws:
FileSystemException- if an error occurs.- See Also:
-
addProvider
Registers a file system provider.The manager takes care of all lifecycle management. A provider may be registered multiple times. The first
LocalFileProvideradded will be remembered forgetLocalFileProvider().- Parameters:
urlScheme- The scheme the provider will handle.provider- The provider.- Throws:
FileSystemException- if an error occurs adding the provider.
-
addProvider
Registers a file system provider.The manager takes care of all lifecycle management. A provider may be registered multiple times. The first
LocalFileProvideradded will be remembered forgetLocalFileProvider().- Parameters:
urlSchemes- The schemes the provider will handle.provider- The provider.- Throws:
FileSystemException- if an error occurs adding the provider.
-
addVirtualFileSystemScheme
-
canCreateFileSystem
Determines if a layered file system can be created for a given file.- Specified by:
canCreateFileSystemin interfaceFileSystemManager- Parameters:
file- The file to check for.- Returns:
- true if the FileSystem can be created.
- Throws:
FileSystemException- if an error occurs.
-
close
public void close()Closes the manager.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.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceFileSystemManager
-
closeComponent
Closes a component, if it has not already been closed.- Parameters:
component- The component to close.
-
closeFileSystem
Closes the given file system.If you use VFS as singleton it is VERY dangerous to call this method.
- Specified by:
closeFileSystemin interfaceFileSystemManager- Parameters:
fileSystem- The FileSystem to close.
-
createFileSystem
Creates a layered file system.- Specified by:
createFileSystemin interfaceFileSystemManager- Parameters:
file- The FileObject to use.- Returns:
- The layered FileObject.
- Throws:
FileSystemException- if an error occurs.
-
createFileSystem
Creates a layered file system.- Specified by:
createFileSystemin interfaceFileSystemManager- Parameters:
scheme- The scheme to use.file- The FileObject.- Returns:
- The layered FileObject.
- Throws:
FileSystemException- if an error occurs.
-
createVirtualFileSystem
Creates a virtual file system.- Specified by:
createVirtualFileSystemin interfaceFileSystemManager- Parameters:
rootFile- The FileObject to use.- Returns:
- The FileObject in the VirtualFileSystem.
- Throws:
FileSystemException- if an error occurs creating the file.
-
createVirtualFileSystem
Creates an empty virtual file system.- Specified by:
createVirtualFileSystemin interfaceFileSystemManager- Parameters:
rootUri- The URI to use as the root of the FileSystem.- Returns:
- A FileObject in the virtual FileSystem.
- Throws:
FileSystemException- if an error occurs.
-
freeUnusedResources
public void freeUnusedResources()Free all resources used by unused file systems created by this manager. -
getBaseFile
Returns the base file used to resolve relative URI.- Specified by:
getBaseFilein interfaceFileSystemManager- Returns:
- The FileObject that represents the base file.
- Throws:
FileSystemException- if an error occurs.
-
getCacheStrategy
Get the cache strategy used.- Specified by:
getCacheStrategyin interfaceFileSystemManager- Returns:
- The CacheStrategy.
-
getFileContentInfoFactory
get the fileContentInfoFactory used to determine the infos of a file content.- Specified by:
getFileContentInfoFactoryin interfaceFileSystemManager- Returns:
- The FileContentInfoFactory.
-
getFileObjectDecorator
Get the file object decorator used.- Specified by:
getFileObjectDecoratorin interfaceFileSystemManager- Returns:
- The decorator.
-
getFileObjectDecoratorConst
The constructor associated to the fileObjectDecorator. We cache it here for performance reasons.- Specified by:
getFileObjectDecoratorConstin interfaceFileSystemManager- Returns:
- The decorator's Constructor.
-
getFilesCache
Returns the filesCache implementation used to cache files.- Specified by:
getFilesCachein interfaceFileSystemManager- Returns:
- The FilesCache.
-
getFileSystemConfigBuilder
Get the configuration builder for the given scheme.- Specified by:
getFileSystemConfigBuilderin interfaceFileSystemManager- Parameters:
scheme- The scheme to locate.- Returns:
- The FileSystemConfigBuilder for the scheme.
- Throws:
FileSystemException- if the given scheme is not konwn
-
getLocalFileProvider
Locates the local file provider.The local file provider is the first provider added implementing
LocalFileProvider.- Returns:
- The LocalFileProvider.
- Throws:
FileSystemException- if no local file provider was set.
-
getLogger
protected org.apache.commons.logging.Log getLogger()Returns the logger used by this manager.- Returns:
- the Logger.
-
getOperationProviders
Description copied from interface:FileSystemManagerGets Providers for file operations.- Specified by:
getOperationProvidersin interfaceFileSystemManager- Parameters:
scheme- the scheme for wich 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
Get the capabilities for a given scheme.- Specified by:
getProviderCapabilitiesin interfaceFileSystemManager- Parameters:
scheme- The scheme to located.- Returns:
- A Collection of capabilities.
- Throws:
FileSystemException- if the given scheme is not konwn
-
getReplicator
Returns the file replicator.- Returns:
- The file replicator. Never returns null.
- Throws:
FileSystemException- if there is no FileReplicator.
-
getSchemes
Get the schemes currently available.- Specified by:
getSchemesin interfaceFileSystemManager- Returns:
- The array of scheme names.
-
getTemporaryFileStore
Returns the temporary file store.- Returns:
- The file store. Never returns null.
- Throws:
FileSystemException- if there is no TemporaryFileStore.
-
getURLStreamHandlerFactory
Get the URLStreamHandlerFactory.- Specified by:
getURLStreamHandlerFactoryin interfaceFileSystemManager- Returns:
- The URLStreamHandlerFactory.
-
hasProvider
Returns true if this manager has a provider for a particular scheme.- Specified by:
hasProviderin interfaceFileSystemManager- Parameters:
scheme- The scheme to check.- Returns:
- true if a provider is configured for this scheme, false otherwise.
-
init
Initializes this manager.If no value for the following properties was specified, it will use the following defaults:
- fileContentInfoFactory = new FileContentInfoFilenameFactory()
- filesCache = new SoftRefFilesCache()
- fileCacheStrategy = CacheStrategy.ON_RESOLVE
- Throws:
FileSystemException- if an error occurs during initialization.
-
removeProvider
Unregisters a file system provider.- Parameters:
urlScheme- The scheme of the provider.- Since:
- 2.8.0
-
resolveFile
Resolves a URI, relative to base file.Uses the local file provider to locate the system file.
- Specified by:
resolveFilein interfaceFileSystemManager- Parameters:
baseFile- The base File to use to locate the file.uri- The URI of the file to locate.- Returns:
- The FileObject for the located file.
- Throws:
FileSystemException- if the file cannot be located or an error occurs.
-
resolveFile
Resolves a URI, relative to a base file.- Specified by:
resolveFilein interfaceFileSystemManager- Parameters:
baseFile- The base FileOjbect to use to locate the file.uri- The URI of the file to locate.- Returns:
- The FileObject for the located file.
- Throws:
FileSystemException- if the file cannot be located or an error occurs.
-
resolveFile
public FileObject resolveFile(FileObject baseFile, String uri, FileSystemOptions fileSystemOptions) throws FileSystemException Resolves a URI, relative to a base file with specified FileSystem configuration.- Parameters:
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.- Returns:
- A FileObject representing the target file.
- Throws:
FileSystemException- if an error occurs accessing the file.
-
resolveFile
Locates a file by URI.- Specified by:
resolveFilein interfaceFileSystemManager- Parameters:
uri- The URI of the file to locate.- Returns:
- The FileObject for the located file.
- Throws:
FileSystemException- if the file cannot be located or an error occurs.
-
resolveFile
public FileObject resolveFile(String uri, FileSystemOptions fileSystemOptions) throws FileSystemException Locate a file by URI, use the FileSystemOptions for file-system creation.- Specified by:
resolveFilein interfaceFileSystemManager- Parameters:
uri- The URI of the file to locate.fileSystemOptions- The options for the FileSystem.- Returns:
- The FileObject for the located file.
- Throws:
FileSystemException- if the file cannot be located or an error occurs.
-
resolveFile
Converts a URI into aFileObject.- Specified by:
resolveFilein interfaceFileSystemManager- Parameters:
uri- The URI to convert.- Returns:
- The
FileObjectthat represents the URI. Never returns null. - Throws:
FileSystemException- On error converting the URI.- Since:
- 2.1
-
resolveFile
Converts a URL into aFileObject.- Specified by:
resolveFilein interfaceFileSystemManager- Parameters:
url- The URL to convert.- Returns:
- The
FileObjectthat represents the URL. Never returns null. - Throws:
FileSystemException- On error converting the URL.- Since:
- 2.1
-
resolveName
Resolves a name, relative to the file. If the supplied name is an absolute path, then it is resolved relative to the root of the file system that the file belongs to. If a relative name is supplied, then it is resolved relative to this file name.- Specified by:
resolveNamein interfaceFileSystemManager- Parameters:
root- The base FileName.path- The path to the file relative to the base FileName or an absolute path.- Returns:
- The constructed FileName.
- Throws:
FileSystemException- if an error occurs constructing the FileName.
-
resolveName
Resolves a name, relative to the root.- Specified by:
resolveNamein interfaceFileSystemManager- Parameters:
base- the base file namename- the namescope- theNameScope- Returns:
- The FileName of the file.
- Throws:
FileSystemException- if an error occurs.
-
resolveURI
Resolve the uri to a file name.- Specified by:
resolveURIin interfaceFileSystemManager- Parameters:
uri- The URI to resolve.- Returns:
- The FileName of the file.
- Throws:
FileSystemException- if an error occurs.
-
setBaseFile
Sets the base file to use when resolving relative URI.- Parameters:
baseFile- The new base FileObject.- Throws:
FileSystemException- if an error occurs.
-
setBaseFile
Sets the base file to use when resolving relative URI.- Parameters:
baseFile- The new base FileObject.
-
setCacheStrategy
Set the cache strategy to use when dealing with file object data.Can only be set before the FileSystemManager is initialized.
The default is
CacheStrategy.ON_RESOLVE.- Parameters:
fileCacheStrategy- The CacheStrategy to use.- Throws:
FileSystemException- if this is not possible. e.g. it is already set.
-
setDefaultProvider
Sets the default provider. This is the provider that will handle URI with unknown schemes. The manager takes care of all lifecycle management.- Parameters:
provider- The FileProvider.- Throws:
FileSystemException- if an error occurs setting the provider.
-
setFileContentInfoFactory
public void setFileContentInfoFactory(FileContentInfoFactory fileContentInfoFactory) throws FileSystemException set the fileContentInfoFactory used to determine the infos of a file content.Can only be set before the FileSystemManager is initialized.
- Parameters:
fileContentInfoFactory- The FileContentInfoFactory.- Throws:
FileSystemException- if an error occurs setting the FileContentInfoFactory.
-
setFileObjectDecorator
Set a fileObject decorator to be used for ALL returned file objects.Can only be set before the FileSystemManager is initialized.
- Parameters:
fileObjectDecorator- must be inherted fromDecoratedFileObjecta has to provide a constructor with a singleFileObjectas argument- Throws:
FileSystemException- if an error occurs setting the decorator.
-
setFilesCache
Sets the filesCache implementation used to cache files.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().- Parameters:
filesCache- The FilesCache.- Throws:
FileSystemException- if an error occurs setting the cache..
-
setLogger
public void setLogger(org.apache.commons.logging.Log log) Sets the logger to use.This overwrites the default logger for this manager and is not reset in
close().- Specified by:
setLoggerin interfaceFileSystemManager- Parameters:
log- The Logger to use.
-
setReplicator
Sets the file replicator to use.The manager takes care of all lifecycle management.
- Parameters:
replicator- The FileReplicator.- Throws:
FileSystemException- if an error occurs setting the replicator.
-
setTemporaryFileStore
Sets the temporary file store to use.The manager takes care of all lifecycle management.
- Parameters:
tempFileStore- The temporary FileStore.- Throws:
FileSystemException- if an error occurs adding the file store.
-
setupComponent
Initializes a component, if it has not already been initialized.- Parameters:
component- The component to setup.- Throws:
FileSystemException- if an error occurs.
-
toFileObject
Converts a local file into aFileObject.- Specified by:
toFileObjectin interfaceFileSystemManager- Parameters:
file- The input File.- Returns:
- the create FileObject
- Throws:
FileSystemException- if an error occurs creating the file.
-