Class SMBFileSystemProvider


  • public final class SMBFileSystemProvider
    extends java.nio.file.spi.FileSystemProvider
    This class acts as a service-provider class for SMB/CIFS based file systems. Internally, it uses jCIFS to provide all the file access functionality.
    Since:
    1.0.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkAccess​(java.nio.file.Path path, java.nio.file.AccessMode... modes)
      Checks access to file under the provided SMBPath.
      void copy​(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)
      Copies the file under provided source SMBPath to the destination SMBPath.
      void createDirectory​(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)
      Creates a directory under the provided SMBPath
      void delete​(java.nio.file.Path path)
      Deletes the file under the provided SMBPath
      <V extends java.nio.file.attribute.FileAttributeView>
      V
      getFileAttributeView​(java.nio.file.Path path, java.lang.Class<V> type, java.nio.file.LinkOption... options)
      Reads the file attributes view of the file under the provided SMBPath and returns it.
      java.nio.file.FileStore getFileStore​(java.nio.file.Path path)  
      SMBFileSystem getFileSystem​(java.net.URI uri)
      Retrieves a SMBFileSystem instance for the provided URI from fileSystemCache and returns it.
      SMBPath getPath​(java.net.URI uri)
      Converts the provided URI to an SMBPath instance and returns it.
      java.lang.String getScheme()
      Returns the default scheme for SMBFileSystemProvider.
      boolean isHidden​(java.nio.file.Path path)
      Returns true, if the resource specified by the provided SMBPath instance is hidden..
      boolean isSameFile​(java.nio.file.Path path1, java.nio.file.Path path2)
      Returns true, if the resources specified by the two SMBPath instance are the same.
      void move​(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)
      Moves the file under the provided source SMBPath to the destination SMBPath.
      java.nio.channels.SeekableByteChannel newByteChannel​(java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs)
      Creates and returns a new SeekableSMBByteChannel instance.
      java.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream​(java.nio.file.Path dir, java.nio.file.DirectoryStream.Filter<? super java.nio.file.Path> filter)
      Creates and returns a new SMBDirectoryStream for the specified path.
      SMBFileSystem newFileSystem​(java.net.URI uri, java.util.Map<java.lang.String,​?> env)
      Creates a new SMBFileSystem instance for the provided URI.
      <A extends java.nio.file.attribute.BasicFileAttributes>
      A
      readAttributes​(java.nio.file.Path path, java.lang.Class<A> type, java.nio.file.LinkOption... options)
      Reads the file attributes of the file under the provided SMBPath and returns it.
      java.util.Map<java.lang.String,​java.lang.Object> readAttributes​(java.nio.file.Path path, java.lang.String attributes, java.nio.file.LinkOption... options)  
      void setAttribute​(java.nio.file.Path path, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options)  
      • Methods inherited from class java.nio.file.spi.FileSystemProvider

        createLink, createSymbolicLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileChannel, newFileSystem, newInputStream, newOutputStream, readSymbolicLink
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • getScheme

        public java.lang.String getScheme()
        Returns the default scheme for SMBFileSystemProvider.
        Specified by:
        getScheme in class java.nio.file.spi.FileSystemProvider
        Returns:
        URI Scheme - 'smb'
      • newFileSystem

        public SMBFileSystem newFileSystem​(java.net.URI uri,
                                           java.util.Map<java.lang.String,​?> env)
        Creates a new SMBFileSystem instance for the provided URI. SMBFileSystem instances are cached based on the authority part of the URI (i.e. URI's with the same authority share the same SMBFileSystem instance). Credentials for connecting with the SMB/CIFS server can be provided in several ways:
        1. Encode in the URI, e.g. smb://WORKGROUP;admin:1234@192.168.1.10
        2. Provide in the env Map. To do so, you have to set the keys 'workgroup', 'username' and 'password'.
        3. Provide in the jCIFS config. See jCIFS documentation for more information.
        The above options will be considered according to precedence. That is, if the credentials are encoded in the URI those provided in the env map or the jCIFS config will be ignored.
        Specified by:
        newFileSystem in class java.nio.file.spi.FileSystemProvider
        Parameters:
        uri - URI for which to create SMBFileSystem
        env - Map containing configuration parameters.
        Returns:
        Newly created SMBFileSystem instance
        Throws:
        java.nio.file.FileSystemAlreadyExistsException - If an instance of SMBFileSystem already exists for provided URI.
        java.lang.IllegalArgumentException - If provided URI is not an SMB URI.
      • getFileSystem

        public SMBFileSystem getFileSystem​(java.net.URI uri)
        Retrieves a SMBFileSystem instance for the provided URI from fileSystemCache and returns it. SMBFileSystem instances are cached based on the authority part of the URI (i.e. URI's with the same authority share the same SMBFileSystem instance).
        Specified by:
        getFileSystem in class java.nio.file.spi.FileSystemProvider
        Parameters:
        uri - URI for which to fetch SMBFileSystem
        Returns:
        SMBFileSystem instance
        Throws:
        java.nio.file.FileSystemNotFoundException - If no instance of SMBFileSystem could be retrieved from fileSystemCache.
        java.lang.IllegalArgumentException - If provided URI is not an SMB URI.
      • getPath

        public SMBPath getPath​(java.net.URI uri)
        Converts the provided URI to an SMBPath instance and returns it. Automatically links the SMBPath with the SMBFileSystem associated with its authority.
        Specified by:
        getPath in class java.nio.file.spi.FileSystemProvider
        Parameters:
        uri - The URI from which to create the SMBPath
        Returns:
        Newly created SMBPath.
        Throws:
        java.lang.IllegalArgumentException - If URI is not an SMB URI.
      • newByteChannel

        public java.nio.channels.SeekableByteChannel newByteChannel​(java.nio.file.Path path,
                                                                    java.util.Set<? extends java.nio.file.OpenOption> options,
                                                                    java.nio.file.attribute.FileAttribute<?>... attrs)
                                                             throws java.io.IOException
        Creates and returns a new SeekableSMBByteChannel instance.
        Specified by:
        newByteChannel in class java.nio.file.spi.FileSystemProvider
        Parameters:
        path - The SMBPath for which a byte channel should be opened.
        options - A set of StandardOpenOptions.
        attrs - An optional list of file attributes to set when creating the file.
        Returns:
        An instance of SeekableSMBByteChannel.
        Throws:
        java.lang.IllegalArgumentException - If provided path is not an SMBPath instance.
        java.io.IOException - If an I/O error occurs
        java.lang.UnsupportedOperationException - If an unsupported open option is specified (DSYNC, SYNC or SPARSE)
      • newDirectoryStream

        public java.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream​(java.nio.file.Path dir,
                                                                                    java.nio.file.DirectoryStream.Filter<? super java.nio.file.Path> filter)
                                                                             throws java.io.IOException
        Creates and returns a new SMBDirectoryStream for the specified path.
        Specified by:
        newDirectoryStream in class java.nio.file.spi.FileSystemProvider
        Parameters:
        dir - The SMBPath for which to create a new DirectoryStream.
        filter - An optional filter that should be applied to filter entries in the stream.
        Returns:
        An instance of SMBDirectoryStream.
        Throws:
        java.lang.IllegalArgumentException - If provided path is not an SMBPath instance.
        java.nio.file.NotDirectoryException - If provided SMBPath does not point to a directory
        java.io.IOException - If an I/O error occurs
      • createDirectory

        public void createDirectory​(java.nio.file.Path dir,
                                    java.nio.file.attribute.FileAttribute<?>... attrs)
                             throws java.io.IOException
        Creates a directory under the provided SMBPath
        Specified by:
        createDirectory in class java.nio.file.spi.FileSystemProvider
        Parameters:
        dir - SMBPath to folder that should be created.
        Throws:
        java.lang.IllegalArgumentException - If provided path is not an SMBPath instance.
        java.nio.file.FileAlreadyExistsException - if a directory could not otherwise be created because a file of that name already exists (optional specific exception)
        java.io.IOException - If creating the folder fails for some reason.
      • delete

        public void delete​(java.nio.file.Path path)
                    throws java.io.IOException
        Deletes the file under the provided SMBPath
        Specified by:
        delete in class java.nio.file.spi.FileSystemProvider
        Parameters:
        path - SMBPath to file that should be deleted.
        Throws:
        java.lang.IllegalArgumentException - If provided path is not an SMBPath instance.
        java.nio.file.NoSuchFileException - if the file does not exist (optional specific exception)
        java.io.IOException - If deleting the file fails for some reason.
      • copy

        public void copy​(java.nio.file.Path source,
                         java.nio.file.Path target,
                         java.nio.file.CopyOption... options)
                  throws java.io.IOException
        Copies the file under provided source SMBPath to the destination SMBPath. Some CopyOptions are ignored!
        Specified by:
        copy in class java.nio.file.spi.FileSystemProvider
        Parameters:
        source - Source SMBPath
        target - Destination SMBPath
        options - CopyOptions
        Throws:
        java.lang.IllegalArgumentException - If provided paths are not SMBPath instances.
        java.nio.file.NoSuchFileException - if the file does not exist (optional specific exception)
        java.nio.file.FileAlreadyExistsException - if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception)
        java.io.IOException - If copying fails for some reason.
      • move

        public void move​(java.nio.file.Path source,
                         java.nio.file.Path target,
                         java.nio.file.CopyOption... options)
                  throws java.io.IOException
        Moves the file under the provided source SMBPath to the destination SMBPath. Some CopyOptions are ignored!
        Specified by:
        move in class java.nio.file.spi.FileSystemProvider
        Parameters:
        source - Source SMBPath
        target - Destination SMBPath
        options - CopyOptions
        Throws:
        java.lang.IllegalArgumentException - If provided paths are not SMBPath instances.
        java.nio.file.NoSuchFileException - if the file does not exist (optional specific exception)
        java.nio.file.FileAlreadyExistsException - if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception)
        java.io.IOException - If moving fails for some reason.
      • isSameFile

        public boolean isSameFile​(java.nio.file.Path path1,
                                  java.nio.file.Path path2)
                           throws java.io.IOException
        Returns true, if the resources specified by the two SMBPath instance are the same.
        Specified by:
        isSameFile in class java.nio.file.spi.FileSystemProvider
        Parameters:
        path1 - First SMBPath
        path2 - Second SMBPath
        Returns:
        True if the two paths point to the same resource.
        Throws:
        java.lang.IllegalArgumentException - If provided paths are not SMBPath instances.
        java.io.IOException - If an I/O error occurs.
      • isHidden

        public boolean isHidden​(java.nio.file.Path path)
                         throws java.io.IOException
        Returns true, if the resource specified by the provided SMBPath instance is hidden..
        Specified by:
        isHidden in class java.nio.file.spi.FileSystemProvider
        Parameters:
        path - SMBPath that should be checked.
        Returns:
        True if the resource under SMBPath is hidden.
        Throws:
        java.lang.IllegalArgumentException - If provided paths are not SMBPath instances.
        java.io.IOException - If an I/O error occurs.
      • checkAccess

        public void checkAccess​(java.nio.file.Path path,
                                java.nio.file.AccessMode... modes)
                         throws java.io.IOException
        Checks access to file under the provided SMBPath.
        Specified by:
        checkAccess in class java.nio.file.spi.FileSystemProvider
        Parameters:
        path - SMBPath for which access should be checked.
        modes - AccessModes that should be checked. Onl yREAD and WRITE are supported.
        Throws:
        java.nio.file.NoSuchFileException - If file or folder specified by SMBPath does not exist.
        java.nio.file.AccessDeniedException - If requested access cannot be provided for file or folder under SMBPath.
        java.lang.IllegalArgumentException - If provided path is not a SMBPath instance.
        java.io.IOException - If checking access fails for some reason.
      • getFileAttributeView

        public <V extends java.nio.file.attribute.FileAttributeView> V getFileAttributeView​(java.nio.file.Path path,
                                                                                            java.lang.Class<V> type,
                                                                                            java.nio.file.LinkOption... options)
        Reads the file attributes view of the file under the provided SMBPath and returns it. LinkOption will be ignored as the SMB filesystem does not support symlinks.
        Specified by:
        getFileAttributeView in class java.nio.file.spi.FileSystemProvider
        Type Parameters:
        V - Type of the class that's being returned.
        Parameters:
        path - SMBPath for which attributes view should be created.
        type - Class of the attributes view. Must be either BasicFileAttributeView or SMBFileAttributeView
        options - LinkOptions; will be ignored.
        Returns:
        SMBFileAttributeView
        Throws:
        java.lang.IllegalArgumentException - If provided paths is not a SMBPath instance.
      • readAttributes

        public <A extends java.nio.file.attribute.BasicFileAttributes> A readAttributes​(java.nio.file.Path path,
                                                                                        java.lang.Class<A> type,
                                                                                        java.nio.file.LinkOption... options)
                                                                                 throws java.io.IOException
        Reads the file attributes of the file under the provided SMBPath and returns it. LinkOption will be ignored as the SMB filesystem does not support symlinks.
        Specified by:
        readAttributes in class java.nio.file.spi.FileSystemProvider
        Type Parameters:
        A - Type of the class that's being returned.
        Parameters:
        path - SMBPath for which attributes should be read.
        type - Class of the attribute. Must be either BasicFileAttributes or SMBFileAttributes
        options - LinkOptions; will be ignored.
        Returns:
        SMBFileAttributes
        Throws:
        java.lang.IllegalArgumentException - If provided paths is not a SMBPath instance.
        java.io.IOException - If reading attributes fails for some reason.
      • readAttributes

        public java.util.Map<java.lang.String,​java.lang.Object> readAttributes​(java.nio.file.Path path,
                                                                                     java.lang.String attributes,
                                                                                     java.nio.file.LinkOption... options)
        Specified by:
        readAttributes in class java.nio.file.spi.FileSystemProvider
      • setAttribute

        public void setAttribute​(java.nio.file.Path path,
                                 java.lang.String attribute,
                                 java.lang.Object value,
                                 java.nio.file.LinkOption... options)
        Specified by:
        setAttribute in class java.nio.file.spi.FileSystemProvider
      • getFileStore

        public java.nio.file.FileStore getFileStore​(java.nio.file.Path path)
        Specified by:
        getFileStore in class java.nio.file.spi.FileSystemProvider