Package ch.pontius.nio.smb
Class SMBFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- ch.pontius.nio.smb.SMBFileSystemProvider
-
public final class SMBFileSystemProvider extends java.nio.file.spi.FileSystemProviderThis 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
-
-
Constructor Summary
Constructors Constructor Description SMBFileSystemProvider()Default constructor forSMBFileSystemProvider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckAccess(java.nio.file.Path path, java.nio.file.AccessMode... modes)Checks access to file under the providedSMBPath.voidcopy(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)voidcreateDirectory(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)Creates a directory under the providedSMBPathvoiddelete(java.nio.file.Path path)Deletes the file under the providedSMBPathjcifs.CIFSContextgetContext()<V extends java.nio.file.attribute.FileAttributeView>
VgetFileAttributeView(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 providedSMBPathand returns it.java.nio.file.FileStoregetFileStore(java.nio.file.Path path)SMBFileSystemgetFileSystem(java.net.URI uri)Retrieves aSMBFileSysteminstance for the provided URI from fileSystemCache and returns it.SMBPathgetPath(java.net.URI uri)Converts the provided URI to anSMBPathinstance and returns it.java.lang.StringgetScheme()Returns the default scheme forSMBFileSystemProvider.booleanisHidden(java.nio.file.Path path)Returns true, if the resource specified by the providedSMBPathinstance is hidden..booleanisSameFile(java.nio.file.Path path1, java.nio.file.Path path2)Returns true, if the resources specified by the twoSMBPathinstance are the same.voidmove(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)java.nio.channels.SeekableByteChannelnewByteChannel(java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs)Creates and returns a newSeekableSMBByteChannelinstance.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 newSMBDirectoryStreamfor the specified path.SMBFileSystemnewFileSystem(java.net.URI uri, java.util.Map<java.lang.String,?> env)Creates a newSMBFileSysteminstance for the provided URI.<A extends java.nio.file.attribute.BasicFileAttributes>
AreadAttributes(java.nio.file.Path path, java.lang.Class<A> type, java.nio.file.LinkOption... options)Reads the file attributes of the file under the providedSMBPathand 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)voidsetAttribute(java.nio.file.Path path, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options)
-
-
-
Constructor Detail
-
SMBFileSystemProvider
public SMBFileSystemProvider()
Default constructor forSMBFileSystemProvider.
-
-
Method Detail
-
getScheme
public java.lang.String getScheme()
Returns the default scheme forSMBFileSystemProvider.- Specified by:
getSchemein classjava.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 newSMBFileSysteminstance for the provided URI.SMBFileSysteminstances are cached based on the authority part of the URI (i.e. URI's with the same authority share the sameSMBFileSysteminstance). Credentials for connecting with the SMB/CIFS server can be provided in several ways:- Encode in the URI, e.g. smb://WORKGROUP;admin:1234@192.168.1.10
- Provide in the env Map. To do so, you have to set the keys 'workgroup', 'username' and 'password'.
- Provide in the jCIFS config. See jCIFS documentation for more information.
- Specified by:
newFileSystemin classjava.nio.file.spi.FileSystemProvider- Parameters:
uri- URI for which to createSMBFileSystemenv- Map containing configuration parameters.- Returns:
- Newly created
SMBFileSysteminstance - Throws:
java.nio.file.FileSystemAlreadyExistsException- If an instance ofSMBFileSystemalready exists for provided URI.java.lang.IllegalArgumentException- If provided URI is not an SMB URI.
-
getFileSystem
public SMBFileSystem getFileSystem(java.net.URI uri)
Retrieves aSMBFileSysteminstance for the provided URI from fileSystemCache and returns it.SMBFileSysteminstances are cached based on the authority part of the URI (i.e. URI's with the same authority share the sameSMBFileSysteminstance).- Specified by:
getFileSystemin classjava.nio.file.spi.FileSystemProvider- Parameters:
uri- URI for which to fetchSMBFileSystem- Returns:
SMBFileSysteminstance- Throws:
java.nio.file.FileSystemNotFoundException- If no instance ofSMBFileSystemcould 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 anSMBPathinstance and returns it. Automatically links theSMBPathwith theSMBFileSystemassociated with its authority.
-
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.IOExceptionCreates and returns a newSeekableSMBByteChannelinstance.- Specified by:
newByteChannelin classjava.nio.file.spi.FileSystemProvider- Parameters:
path- TheSMBPathfor which a byte channel should be opened.options- A set ofStandardOpenOptions.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 anSMBPathinstance.java.io.IOException- If an I/O error occursjava.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.IOExceptionCreates and returns a newSMBDirectoryStreamfor the specified path.- Specified by:
newDirectoryStreamin classjava.nio.file.spi.FileSystemProvider- Parameters:
dir- TheSMBPathfor 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 anSMBPathinstance.java.nio.file.NotDirectoryException- If providedSMBPathdoes not point to a directoryjava.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.IOExceptionCreates a directory under the providedSMBPath- Specified by:
createDirectoryin classjava.nio.file.spi.FileSystemProvider- Parameters:
dir-SMBPathto folder that should be created.- Throws:
java.lang.IllegalArgumentException- If provided path is not anSMBPathinstance.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.IOExceptionDeletes the file under the providedSMBPath- Specified by:
deletein classjava.nio.file.spi.FileSystemProvider- Parameters:
path-SMBPathto file that should be deleted.- Throws:
java.lang.IllegalArgumentException- If provided path is not anSMBPathinstance.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.IOExceptionCopies the file under provided sourceSMBPathto the destinationSMBPath. Some CopyOptions are ignored!- Specified by:
copyin classjava.nio.file.spi.FileSystemProvider- Parameters:
source- SourceSMBPathtarget- DestinationSMBPathoptions- CopyOptions- Throws:
java.lang.IllegalArgumentException- If provided paths are notSMBPathinstances.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 theREPLACE_EXISTINGoption 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.IOExceptionMoves the file under the provided sourceSMBPathto the destinationSMBPath. Some CopyOptions are ignored!- Specified by:
movein classjava.nio.file.spi.FileSystemProvider- Parameters:
source- SourceSMBPathtarget- DestinationSMBPathoptions- CopyOptions- Throws:
java.lang.IllegalArgumentException- If provided paths are notSMBPathinstances.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 theREPLACE_EXISTINGoption 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.IOExceptionReturns true, if the resources specified by the twoSMBPathinstance are the same.- Specified by:
isSameFilein classjava.nio.file.spi.FileSystemProvider- Parameters:
path1- FirstSMBPathpath2- SecondSMBPath- Returns:
- True if the two paths point to the same resource.
- Throws:
java.lang.IllegalArgumentException- If provided paths are notSMBPathinstances.java.io.IOException- If an I/O error occurs.
-
isHidden
public boolean isHidden(java.nio.file.Path path) throws java.io.IOExceptionReturns true, if the resource specified by the providedSMBPathinstance is hidden..- Specified by:
isHiddenin classjava.nio.file.spi.FileSystemProvider- Parameters:
path-SMBPaththat should be checked.- Returns:
- True if the resource under
SMBPathis hidden. - Throws:
java.lang.IllegalArgumentException- If provided paths are notSMBPathinstances.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.IOExceptionChecks access to file under the providedSMBPath.- Specified by:
checkAccessin classjava.nio.file.spi.FileSystemProvider- Parameters:
path-SMBPathfor 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 bySMBPathdoes not exist.java.nio.file.AccessDeniedException- If requested access cannot be provided for file or folder underSMBPath.java.lang.IllegalArgumentException- If provided path is not aSMBPathinstance.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 providedSMBPathand returns it. LinkOption will be ignored as the SMB filesystem does not support symlinks.- Specified by:
getFileAttributeViewin classjava.nio.file.spi.FileSystemProvider- Type Parameters:
V- Type of the class that's being returned.- Parameters:
path-SMBPathfor which attributes view should be created.type- Class of the attributes view. Must be eitherBasicFileAttributeVieworSMBFileAttributeViewoptions- LinkOptions; will be ignored.- Returns:
SMBFileAttributeView- Throws:
java.lang.IllegalArgumentException- If provided paths is not aSMBPathinstance.
-
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.IOExceptionReads the file attributes of the file under the providedSMBPathand returns it. LinkOption will be ignored as the SMB filesystem does not support symlinks.- Specified by:
readAttributesin classjava.nio.file.spi.FileSystemProvider- Type Parameters:
A- Type of the class that's being returned.- Parameters:
path-SMBPathfor which attributes should be read.type- Class of the attribute. Must be eitherBasicFileAttributesorSMBFileAttributesoptions- LinkOptions; will be ignored.- Returns:
SMBFileAttributes- Throws:
java.lang.IllegalArgumentException- If provided paths is not aSMBPathinstance.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:
readAttributesin classjava.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:
setAttributein classjava.nio.file.spi.FileSystemProvider
-
getFileStore
public java.nio.file.FileStore getFileStore(java.nio.file.Path path)
- Specified by:
getFileStorein classjava.nio.file.spi.FileSystemProvider
-
getContext
public jcifs.CIFSContext getContext()
-
-