Class DefaultFileSystemManager

    • Field Detail

      • providers

        private final java.util.Map<java.lang.String,​FileProvider> providers
        Mapping from URI scheme to FileProvider.
      • virtualFileSystemSchemes

        private final java.util.List<java.lang.String> virtualFileSystemSchemes
        List of the schemes of virtual file systems added.
      • components

        private final java.util.ArrayList<java.lang.Object> components
        All components used by this manager.
      • operationProviders

        private final java.util.Map<java.lang.String,​java.util.List<FileOperationProvider>> operationProviders
        Operations providers added to this manager.
      • typeMap

        private final FileTypeMap typeMap
        Mappings of file types.
      • localFileProvider

        private LocalFileProvider localFileProvider
        The provider for local files.
      • defaultProvider

        private FileProvider defaultProvider
        The default provider.
      • fileReplicator

        private FileReplicator fileReplicator
        The file replicator to use.
      • baseFile

        private FileObject baseFile
        The base file to use for relative URI.
      • filesCache

        private FilesCache filesCache
        The files cache
      • fileCacheStrategy

        private CacheStrategy fileCacheStrategy
        The cache strategy
      • fileObjectDecorator

        private java.lang.Class<?> fileObjectDecorator
        Class which decorates all returned fileObjects
      • fileObjectDecoratorConst

        private java.lang.reflect.Constructor<?> fileObjectDecoratorConst
        Reflection constructor extracted from fileObjectDecorator
      • fileContentInfoFactory

        private FileContentInfoFactory fileContentInfoFactory
        The class to use to determine the content-type (mime-type)
      • log

        private org.apache.commons.logging.Log log
        The logger to use. Default implementation.
      • tempFileStore

        private TemporaryFileStore tempFileStore
        The temporary file store to use.
      • init

        private boolean init
        Flag, if manager is initialized (after init() and before close()).
    • Constructor Detail

      • DefaultFileSystemManager

        public DefaultFileSystemManager()
    • Method Detail

      • _closeFileSystem

        public void _closeFileSystem​(FileSystem fileSystem)
        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

        public void addExtensionMap​(java.lang.String extension,
                                    java.lang.String scheme)
        Adds an file name extension mapping.
        Parameters:
        extension - The file name extension.
        scheme - The scheme to use for files with this extension.
      • addMimeTypeMap

        public void addMimeTypeMap​(java.lang.String mimeType,
                                   java.lang.String scheme)
        Adds a mime type mapping.
        Parameters:
        mimeType - The mime type.
        scheme - The scheme to use for files with this mime type.
      • addOperationProvider

        public void addOperationProvider​(java.lang.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:
        addOperationProvider in interface FileSystemManager
        Parameters:
        scheme - The scheme the provider should be registered for.
        operationProvider - The FileOperationProvider.
        Throws:
        FileSystemException - if an error occurs adding the provider.
      • addProvider

        public void addProvider​(java.lang.String urlScheme,
                                FileProvider provider)
                         throws FileSystemException
        Registers a file system provider.

        The manager takes care of all lifecycle management. A provider may be registered multiple times. The first LocalFileProvider added will be remembered for getLocalFileProvider().

        Parameters:
        urlScheme - The scheme the provider will handle.
        provider - The provider.
        Throws:
        FileSystemException - if an error occurs adding the provider.
      • addProvider

        public void addProvider​(java.lang.String[] urlSchemes,
                                FileProvider provider)
                         throws FileSystemException
        Registers a file system provider.

        The manager takes care of all lifecycle management. A provider may be registered multiple times. The first LocalFileProvider added will be remembered for getLocalFileProvider().

        Parameters:
        urlSchemes - The schemes the provider will handle.
        provider - The provider.
        Throws:
        FileSystemException - if an error occurs adding the provider.
      • addVirtualFileSystemScheme

        protected void addVirtualFileSystemScheme​(java.lang.String rootUri)
      • 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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface FileSystemManager
      • closeComponent

        private void closeComponent​(java.lang.Object component)
        Closes a component, if it has not already been closed.
        Parameters:
        component - The component to close.
      • closeFileSystem

        public void closeFileSystem​(FileSystem fileSystem)
        Closes the given file system.

        If you use VFS as singleton it is VERY dangerous to call this method.

        Specified by:
        closeFileSystem in interface FileSystemManager
        Parameters:
        fileSystem - The FileSystem to close.
      • freeUnusedResources

        public void freeUnusedResources()
        Free all resources used by unused file systems created by this manager.
      • getFileObjectDecorator

        public java.lang.Class<?> getFileObjectDecorator()
        Get the file object decorator used.
        Specified by:
        getFileObjectDecorator in interface FileSystemManager
        Returns:
        The decorator.
      • getFileObjectDecoratorConst

        public java.lang.reflect.Constructor<?> getFileObjectDecoratorConst()
        The constructor associated to the fileObjectDecorator. We cache it here for performance reasons.
        Specified by:
        getFileObjectDecoratorConst in interface FileSystemManager
        Returns:
        The decorator's Constructor.
      • getLogger

        protected org.apache.commons.logging.Log getLogger()
        Returns the logger used by this manager.
        Returns:
        the Logger.
      • getOperationProviders

        public FileOperationProvider[] getOperationProviders​(java.lang.String scheme)
                                                      throws FileSystemException
        Description copied from interface: FileSystemManager
        Gets Providers for file operations.
        Specified by:
        getOperationProviders in interface FileSystemManager
        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.
      • getSchemes

        public java.lang.String[] getSchemes()
        Get the schemes currently available.
        Specified by:
        getSchemes in interface FileSystemManager
        Returns:
        The array of scheme names.
      • getURLStreamHandlerFactory

        public java.net.URLStreamHandlerFactory getURLStreamHandlerFactory()
        Get the URLStreamHandlerFactory.
        Specified by:
        getURLStreamHandlerFactory in interface FileSystemManager
        Returns:
        The URLStreamHandlerFactory.
      • hasProvider

        public boolean hasProvider​(java.lang.String scheme)
        Returns true if this manager has a provider for a particular scheme.
        Specified by:
        hasProvider in interface FileSystemManager
        Parameters:
        scheme - The scheme to check.
        Returns:
        true if a provider is configured for this scheme, false otherwise.
      • init

        public void init()
                  throws FileSystemException
        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

        public void removeProvider​(java.lang.String urlScheme)
        Unregisters a file system provider.
        Parameters:
        urlScheme - The scheme of the provider.
        Since:
        2.8.0
      • resolveFile

        public FileObject resolveFile​(java.io.File baseFile,
                                      java.lang.String uri)
                               throws FileSystemException
        Resolves a URI, relative to base file.

        Uses the local file provider to locate the system file.

        Specified by:
        resolveFile in interface FileSystemManager
        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

        public FileObject resolveFile​(FileObject baseFile,
                                      java.lang.String uri)
                               throws FileSystemException
        Resolves a URI, relative to a base file.
        Specified by:
        resolveFile in interface FileSystemManager
        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,
                                      java.lang.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

        public FileObject resolveFile​(java.lang.String uri,
                                      FileSystemOptions fileSystemOptions)
                               throws FileSystemException
        Locate a file by URI, use the FileSystemOptions for file-system creation.
        Specified by:
        resolveFile in interface FileSystemManager
        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.
      • resolveName

        public FileName resolveName​(FileName root,
                                    java.lang.String path)
                             throws FileSystemException
        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:
        resolveName in interface FileSystemManager
        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.
      • setBaseFile

        public void setBaseFile​(java.io.File baseFile)
                         throws FileSystemException
        Sets the base file to use when resolving relative URI.
        Parameters:
        baseFile - The new base FileObject.
        Throws:
        FileSystemException - if an error occurs.
      • setBaseFile

        public void setBaseFile​(FileObject baseFile)
        Sets the base file to use when resolving relative URI.
        Parameters:
        baseFile - The new base FileObject.
      • setCacheStrategy

        public void setCacheStrategy​(CacheStrategy fileCacheStrategy)
                              throws FileSystemException
        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

        public void setDefaultProvider​(FileProvider provider)
                                throws FileSystemException
        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

        public void setFileObjectDecorator​(java.lang.Class<?> fileObjectDecorator)
                                    throws FileSystemException
        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 from DecoratedFileObject a has to provide a constructor with a single FileObject as argument
        Throws:
        FileSystemException - if an error occurs setting the decorator.
      • setFilesCache

        public void setFilesCache​(FilesCache filesCache)
                           throws FileSystemException
        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:
        setLogger in interface FileSystemManager
        Parameters:
        log - The Logger to use.
      • setReplicator

        public void setReplicator​(FileReplicator replicator)
                           throws FileSystemException
        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

        public void setTemporaryFileStore​(TemporaryFileStore tempFileStore)
                                   throws FileSystemException
        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

        private void setupComponent​(java.lang.Object component)
                             throws FileSystemException
        Initializes a component, if it has not already been initialized.
        Parameters:
        component - The component to setup.
        Throws:
        FileSystemException - if an error occurs.