- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
SmbPipeResource
- All Known Implementing Classes:
SmbFile,SmbNamedPipe
SmbFile
may also refer to servers and workgroups.- Author:
- mbechler
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleancanRead()Tests to see if the file thisSmbResourcerepresents can be read.booleancanWrite()Tests to see if the file thisSmbResourcerepresents exists and is not marked read-only.children()Fetch all childrenFetch children matching pattern, server-side filteringchildren(ResourceFilter filter) Fetch children matching the given filter.children(ResourceNameFilter filter) Fetch children matching the given filter.voidclose()Close/release the file This releases all resources that this file holds.voidcopyTo(SmbResource dest) This method will copy the file or directory represented by thisSmbResourceand it's sub-contents to the location specified by thedestparameter.voidCreate a new file but fail if it already exists.longRetrieve the time thisSmbResourcewas created.voiddelete()This method will delete the file or directory specified by thisSmbResource.booleanexists()Tests to see if the SMB resource exists.longGet the file indexintReturn the attributes of this file.The context this file was opened withlongThis method returns the free disk space in bytes of the drive this share represents or the drive on which the directory or file resides.Gets the file locator for this file The file locator provides details aboutgetName()Returns the last component of the target URL.Return the resolved owner group SID for this file or directorygetOwnerGroup(boolean resolve) Return the owner group SID for this file or directoryReturn the resolved owner user SID for this file or directorygetOwnerUser(boolean resolve) Return the owner user SID for this file or directoryACE[]Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.ACE[]getSecurity(boolean resolveSids) Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.ACE[]getShareSecurity(boolean resolveSids) Return an array of Access Control Entry (ACE) objects representing the share permissions on the share exporting this file or directory.intgetType()Returns type of of object thisSmbResourcerepresents.booleanTests to see if the file thisSmbResourcerepresents is a directory.booleanisFile()Tests to see if the file thisSmbResourcerepresents is not a directory.booleanisHidden()Tests to see if the file this SmbResource represents is marked as hidden.longRetrieve the last acces time of the file represented by thisSmbResourcelongRetrieve the last time the file represented by thisSmbResourcewas modified.longlength()Returns the length of thisSmbResourcein bytes.voidmkdir()Creates a directory with the path specified by thisSmbResource.voidmkdirs()Creates a directory with the path specified by thisSmbResourceand any parent directories that do not exist.Opens an input stream reading the file (read only, sharable)openInputStream(int sharing) Opens an input stream reading the file (read only)openInputStream(int flags, int access, int sharing) Opens an input stream reading the file (read only)Opens an output stream writing to the file (truncating, write only, sharable)openOutputStream(boolean append) Opens an output stream writing to the file (write only, read sharable)openOutputStream(boolean append, int sharing) Opens an output stream writing to the file (write only, exclusive write access)openOutputStream(boolean append, int openFlags, int access, int sharing) Opens an output stream writing to the file (write only, exclusive write access)openRandomAccess(String mode) Opens the file for random accessopenRandomAccess(String mode, int sharing) Opens the file for random accessvoidrenameTo(SmbResource dest) Changes the name of the file thisSmbResourcerepresents to the name designated by theSmbResourceargument.voidrenameTo(SmbResource dest, boolean replace) Changes the name of the file thisSmbResourcerepresents to the name designated by theSmbResourceargument.Fetch a child resourcevoidsetAttributes(int attrs) Set the attributes of this file.voidsetCreateTime(long time) Set the create time of the file.voidsetFileTimes(long createTime, long lastModified, long lastAccess) Set the create, last modified and last access time of the file.voidsetLastAccess(long time) Set the last access time of the file.voidsetLastModified(long time) Set the last modified time of the file.voidMake this file read-only.voidTurn off the read-only attribute of this file.watch(int filter, boolean recursive) Creates a directory watch The server will notify the client when there are changes to the directories contents
-
Method Details
-
getLocator
SmbResourceLocator getLocator()Gets the file locator for this file The file locator provides details about- Returns:
- the fileLocator
-
getContext
CIFSContext getContext()The context this file was opened with- Returns:
- the context associated with this file
-
getName
String getName()Returns the last component of the target URL. This will effectively be the name of the file or directory represented by thisSmbResourceor in the case of URLs that only specify a server or workgroup, the server or workgroup will be returned. The name of the root URLsmb://is alsosmb://. If thisSmbResourcerefers to a workgroup, server, share, or directory, the name will include a trailing slash '/' so that composing newSmbResources will maintain the trailing slash requirement.- Returns:
- The last component of the URL associated with this SMB
resource or
smb://if the resource issmb://itself.
-
getType
Returns type of of object thisSmbResourcerepresents.- Returns:
TYPE_FILESYSTEM, TYPE_WORKGROUP, TYPE_SERVER, TYPE_SHARE, TYPE_PRINTER, TYPE_NAMED_PIPE, orTYPE_COMM.- Throws:
CIFSException- if an error occurs accessing the resource
-
exists
Tests to see if the SMB resource exists. If the resource refers only to a server, this method determines if the server exists on the network and is advertising SMB services. If this resource refers to a workgroup, this method determines if the workgroup name is valid on the local SMB network. If thisSmbResourcerefers to the rootsmb://resourcetrueis always returned. If thisSmbResourceis a traditional file or directory, it will be queried for on the specified server as expected.- Returns:
trueif the resource exists or is alive orfalseotherwise- Throws:
CIFSException- if an error occurs accessing the resource
-
resolve
Fetch a child resource- Parameters:
name- the name of the child resource to resolve- Returns:
- the child resource
- Throws:
CIFSException- if an error occurs accessing the resource
-
fileIndex
Get the file index- Returns:
- server side file index, 0 if unavailable
- Throws:
CIFSException- if an error occurs accessing the resource
-
getAttributes
Return the attributes of this file. Attributes are represented as a bitset that must be masked withATTR_*constants to determine if they are set or unset. The value returned is suitable for use with thesetAttributes()method.- Returns:
- the
ATTR_*attributes associated with this file - Throws:
CIFSException- if an error occurs accessing the resource
-
isHidden
Tests to see if the file this SmbResource represents is marked as hidden. This method will also return true for shares with names that end with '$' such asIPC$orC$.- Returns:
trueif theSmbResourceis marked as being hidden- Throws:
CIFSException- if an error occurs accessing the resource
-
isFile
Tests to see if the file thisSmbResourcerepresents is not a directory.- Returns:
trueif thisSmbResourceis not a directory- Throws:
CIFSException- if an error occurs accessing the resource
-
isDirectory
Tests to see if the file thisSmbResourcerepresents is a directory.- Returns:
trueif thisSmbResourceis a directory- Throws:
CIFSException- if an error occurs accessing the resource
-
canWrite
Tests to see if the file thisSmbResourcerepresents exists and is not marked read-only. By default, resources are considered to be read-only and therefore forsmb://,smb://workgroup/, andsmb://server/resources will be read-only.- Returns:
trueif the resource exists is not marked read-only- Throws:
CIFSException- if an error occurs accessing the resource
-
canRead
Tests to see if the file thisSmbResourcerepresents can be read. Because any file, directory, or other resource can be read if it exists, this method simply calls theexistsmethod.- Returns:
trueif the file is read-only- Throws:
CIFSException- if an error occurs accessing the resource
-
setReadWrite
Turn off the read-only attribute of this file. This is shorthand forsetAttributes( getAttributes() & ~ATTR_READONLY ).- Throws:
CIFSException- if an error occurs modifying the resource
-
setReadOnly
Make this file read-only. This is shorthand forsetAttributes( getAttributes() | ATTR_READ_ONLY ).- Throws:
CIFSException- if an error occurs modifying the resource
-
setAttributes
Set the attributes of this file. Attributes are composed into a bitset by bitwise ORing theATTR_*constants. Setting the value returned bygetAttributeswill result in both files having the same attributes.- Parameters:
attrs- attribute flags- Throws:
CIFSException- if an error occurs modifying the resource
-
setFileTimes
Set the create, last modified and last access time of the file. The time is specified as milliseconds from Jan 1, 1970 which is the same as that which is returned by thecreateTime(),lastModified(),lastAccess()methods.
This method does not apply to workgroups, servers, or shares.- Parameters:
createTime- the create time as milliseconds since Jan 1, 1970lastModified- the last modified time as milliseconds since Jan 1, 1970lastAccess- the last access time as milliseconds since Jan 1, 1970- Throws:
CIFSException- if an error occurs modifying the resourceSmbUnsupportedOperationException- if CAP_NT_SMBS is unavailable- See Also:
-
setLastAccess
Set the last access time of the file. The time is specified as milliseconds from Jan 1, 1970 which is the same as that which is returned by thelastAccess()method.
This method does not apply to workgroups, servers, or shares.- Parameters:
time- the last access time as milliseconds since Jan 1, 1970- Throws:
CIFSException- if an error occurs modifying the resourceSmbUnsupportedOperationException- if CAP_NT_SMBS is unavailable
-
setLastModified
Set the last modified time of the file. The time is specified as milliseconds from Jan 1, 1970 which is the same as that which is returned by thelastModified()method.
This method does not apply to workgroups, servers, or shares.- Parameters:
time- the last modified time as milliseconds since Jan 1, 1970- Throws:
CIFSException- if an error occurs modifying the resource
-
setCreateTime
Set the create time of the file. The time is specified as milliseconds from Jan 1, 1970 which is the same as that which is returned by thecreateTime()method.
This method does not apply to workgroups, servers, or shares.- Parameters:
time- the create time as milliseconds since Jan 1, 1970- Throws:
CIFSException- if an error occurs modifying the resourceSmbUnsupportedOperationException- if CAP_NT_SMBS is unavailable
-
lastAccess
Retrieve the last acces time of the file represented by thisSmbResource- Returns:
- The number of milliseconds since the 00:00:00 GMT, January 1,
1970 as a
longvalue - Throws:
CIFSException- if an error occurs accessing the resource
-
lastModified
Retrieve the last time the file represented by thisSmbResourcewas modified. The value returned is suitable for constructing aDateobject (i.e. seconds since Epoch 1970). Times should be the same as those reported using the properties dialog of the Windows Explorer program.- Returns:
- The number of milliseconds since the 00:00:00 GMT, January 1,
1970 as a
longvalue - Throws:
CIFSException- if an error occurs accessing the resource
-
createTime
Retrieve the time thisSmbResourcewas created. The value returned is suitable for constructing aDateobject (i.e. seconds since Epoch 1970). Times should be the same as those reported using the properties dialog of the Windows Explorer program. For Win95/98/Me this is actually the last write time. It is currently not possible to retrieve the create time from files on these systems.- Returns:
- The number of milliseconds since the 00:00:00 GMT, January 1,
1970 as a
longvalue - Throws:
CIFSException- if an error occurs accessing the resource
-
createNewFile
Create a new file but fail if it already exists. The check for existence of the file and it's creation are an atomic operation with respect to other filesystem activities.- Throws:
CIFSException- if an error occurs creating the file
-
mkdirs
Creates a directory with the path specified by thisSmbResourceand any parent directories that do not exist. This method will fail when used withsmb://,smb://workgroup/,smb://server/, orsmb://server/share/URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).- Throws:
CIFSException- if an error occurs creating the directories
-
mkdir
Creates a directory with the path specified by thisSmbResource. For this method to be successful, the target must not already exist. This method will fail when used withsmb://,smb://workgroup/,smb://server/, orsmb://server/share/URLs because workgroups, servers, and shares cannot be dynamically created (although in the future it may be possible to create shares).- Throws:
CIFSException- if an error occurs creating the directory
-
getDiskFreeSpace
This method returns the free disk space in bytes of the drive this share represents or the drive on which the directory or file resides. Objects other thanTYPE_SHAREorTYPE_FILESYSTEMwill result in 0L being returned.- Returns:
- the free disk space in bytes of the drive on which this file or directory resides
- Throws:
CIFSException- if an error occurs accessing the resource
-
length
Returns the length of thisSmbResourcein bytes. If this object is aTYPE_SHAREthe total capacity of the disk shared in bytes is returned. If this object is a directory or a type other thanTYPE_SHARE, 0L is returned.- Returns:
- The length of the file in bytes or 0 if this
SmbResourceis not a file. - Throws:
CIFSException- if an error occurs accessing the resource
-
delete
This method will delete the file or directory specified by thisSmbResource. If the target is a directory, the contents of the directory will be deleted as well. If a file within the directory or it's sub-directories is marked read-only, the read-only status will be removed and the file will be deleted. If the file has been opened before, it will be closed.- Throws:
CIFSException- if an error occurs accessing the resource
-
copyTo
This method will copy the file or directory represented by thisSmbResourceand it's sub-contents to the location specified by thedestparameter. This file and the destination file do not need to be on the same host. This operation does not copy extended file attributes such as ACLs but it does copy regular attributes as well as create and last write times. This method is almost twice as efficient as manually copying as it employs an additional write thread to read and write data concurrently.
It is not possible (nor meaningful) to copy entire workgroups or servers.- Parameters:
dest- the destination file or directory- Throws:
CIFSException- if an error occurs accessing the resource
-
renameTo
Changes the name of the file thisSmbResourcerepresents to the name designated by theSmbResourceargument.
Remember:SmbResources are immutable and therefore the path associated with thisSmbResourceobject will not change). To access the renamed file it is necessary to construct a newSmbResource.- Parameters:
dest- AnSmbResourcethat represents the new pathname- Throws:
CIFSException- if an error occurs renaming the resourceNullPointerException- If thedestargument isnull
-
renameTo
Changes the name of the file thisSmbResourcerepresents to the name designated by theSmbResourceargument.
Remember:SmbResources are immutable and therefore the path associated with thisSmbResourceobject will not change). To access the renamed file it is necessary to construct a newSmbResource.- Parameters:
dest- AnSmbResourcethat represents the new pathnamereplace- Whether an existing destination file should be replaced (only supported with SMB2)- Throws:
CIFSException- if an error occurs renaming the resourceNullPointerException- If thedestargument isnull
-
watch
Creates a directory watch The server will notify the client when there are changes to the directories contents- Parameters:
filter- see constants inFileNotifyInformationrecursive- whether to also watch subdirectories- Returns:
- watch context, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
getOwnerGroup
Return the resolved owner group SID for this file or directory- Returns:
- the owner group SID,
nullif not present - Throws:
IOException- if an I/O error occurs
-
getOwnerGroup
Return the owner group SID for this file or directory- Parameters:
resolve- whether to resolve the group name- Returns:
- the owner group SID,
nullif not present - Throws:
IOException- if an I/O error occurs
-
getOwnerUser
Return the resolved owner user SID for this file or directory- Returns:
- the owner user SID,
nullif not present - Throws:
IOException- if an I/O error occurs
-
getOwnerUser
Return the owner user SID for this file or directory- Parameters:
resolve- whether to resolve the user name- Returns:
- the owner user SID,
nullif not present - Throws:
IOException- if an I/O error occurs
-
getSecurity
Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory.Initially, the SIDs within each ACE will not be resolved however when
getType(),getDomainName(),getAccountName(), ortoString()is called, the names will attempt to be resolved. If the names cannot be resolved (e.g. due to temporary network failure), the said methods will return default values (usuallyS-X-Y-Zstrings of fragments of).Alternatively
getSecurity(true)may be used to resolve all SIDs together and detect network failures.- Returns:
- array of ACEs
- Throws:
IOException- if an I/O error occurs
-
getSecurity
Return an array of Access Control Entry (ACE) objects representing the security descriptor associated with this file or directory. If no DACL is present, null is returned. If the DACL is empty, an array with 0 elements is returned.- Parameters:
resolveSids- Attempt to resolve the SIDs within each ACE form their numeric representation to their corresponding account names.- Returns:
- array of ACEs
- Throws:
IOException- if an I/O error occurs
-
openRandomAccess
Opens the file for random access- Parameters:
mode- access mode (r|rw)sharing- flags indicating for which operations others may concurrently open the file- Returns:
- random access file, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openRandomAccess
Opens the file for random access- Parameters:
mode- access mode (r|rw)- Returns:
- random access file, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openOutputStream
OutputStream openOutputStream(boolean append, int openFlags, int access, int sharing) throws CIFSException Opens an output stream writing to the file (write only, exclusive write access)- Parameters:
append- whether to append to or truncate the inputopenFlags- flags for open operationaccess- desired file access flagssharing- flags indicating for which operations others may open the file- Returns:
- output stream, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openOutputStream
Opens an output stream writing to the file (write only, exclusive write access)- Parameters:
append- whether to append to or truncate the inputsharing- flags indicating for which operations others may open the file (FILE_SHARING_*)- Returns:
- output stream, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openOutputStream
Opens an output stream writing to the file (write only, read sharable)- Parameters:
append- whether to append to or truncate the input- Returns:
- output stream, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openOutputStream
Opens an output stream writing to the file (truncating, write only, sharable)- Returns:
- output stream, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openInputStream
Opens an input stream reading the file (read only)- Parameters:
flags- open flagsaccess- desired access flagssharing- flags indicating for which operations others may open the file (FILE_SHARING_*)- Returns:
- input stream, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openInputStream
Opens an input stream reading the file (read only)- Parameters:
sharing- flags indicating for which operations others may open the file (FILE_SHARING_*)- Returns:
- input stream, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
openInputStream
Opens an input stream reading the file (read only, sharable)- Returns:
- input stream, needs to be closed when finished
- Throws:
CIFSException- if an error occurs accessing the resource
-
close
void close()Close/release the file This releases all resources that this file holds. If not using strict mode this is currently a no-op.- Specified by:
closein interfaceAutoCloseable- See Also:
-
children
Fetch all children- Returns:
- an iterator over the child resources
- Throws:
CIFSException- if an error occurs accessing the resource
-
children
Fetch children matching pattern, server-side filteringThe wildcard expression may consist of two special meta characters in addition to the normal filename characters. The '*' character matches any number of characters in part of a name. If the expression begins with one or more '?'s then exactly that many characters will be matched whereas if it ends with '?'s it will match that many characters or less.
Wildcard expressions will not filter workgroup names or server names.
- Parameters:
wildcard- the wildcard pattern to match- Returns:
- an iterator over the child resources
- Throws:
CIFSException- if an error occurs accessing the resource
-
children
Fetch children matching the given filter.- Parameters:
filter- filter acting on file names- Returns:
- an iterator over the child resources
- Throws:
CIFSException- if an error occurs accessing the resource- See Also:
-
children
Fetch children matching the given filter.- Parameters:
filter- filter acting on SmbResource instances- Returns:
- an iterator over the child resources
- Throws:
CIFSException- if an error occurs accessing the resource- See Also:
-