public interface SmbResource extends AutoCloseable
SmbFile
may also refer to servers and workgroups.for the main implementation of this interface
Modifier and Type | Method and Description |
---|---|
boolean |
canRead()
Tests to see if the file this
SmbResource represents can be
read. |
boolean |
canWrite()
Tests to see if the file this
SmbResource represents
exists and is not marked read-only. |
CloseableIterator<SmbResource> |
children()
Fetch all children
|
CloseableIterator<SmbResource> |
children(ResourceFilter filter) |
CloseableIterator<SmbResource> |
children(ResourceNameFilter filter) |
CloseableIterator<SmbResource> |
children(String wildcard)
Fetch children matching pattern, server-side filtering
|
void |
close()
Close/release the file
This releases all resources that this file holds.
|
void |
copyTo(SmbResource dest)
This method will copy the file or directory represented by this
SmbResource and it's sub-contents to the location specified by the
dest parameter.
|
void |
createNewFile()
Create a new file but fail if it already exists.
|
long |
createTime()
Retrieve the time this
SmbResource was created. |
void |
delete()
This method will delete the file or directory specified by this
SmbResource . |
boolean |
exists()
Tests to see if the SMB resource exists.
|
long |
fileIndex()
Get the file index
|
int |
getAttributes()
Return the attributes of this file.
|
CIFSContext |
getContext()
The context this file was opened with
|
long |
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.
|
SmbResourceLocator |
getLocator()
Gets the file locator for this file
The file locator provides details about
|
String |
getName()
Returns the last component of the target URL.
|
SID |
getOwnerGroup()
Return the resolved owner group SID for this file or directory
|
SID |
getOwnerGroup(boolean resolve)
Return the owner group SID for this file or directory
|
SID |
getOwnerUser()
Return the resolved owner user SID for this file or directory
|
SID |
getOwnerUser(boolean resolve)
Return the owner user SID for this file or directory
|
ACE[] |
getSecurity()
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.
|
int |
getType()
Returns type of of object this SmbResource represents.
|
boolean |
isDirectory()
Tests to see if the file this
SmbResource represents is a directory. |
boolean |
isFile()
Tests to see if the file this
SmbResource represents is not a directory. |
boolean |
isHidden()
Tests to see if the file this SmbResource represents is marked as
hidden.
|
long |
lastAccess()
Retrieve the last acces time of the file represented by this
SmbResource |
long |
lastModified()
Retrieve the last time the file represented by this
SmbResource was modified. |
long |
length()
Returns the length of this SmbResource in bytes.
|
void |
mkdir()
Creates a directory with the path specified by this
SmbResource . |
void |
mkdirs()
Creates a directory with the path specified by this SmbResource
and any parent directories that do not exist.
|
InputStream |
openInputStream()
Opens an input stream reading the file (read only, sharable)
|
InputStream |
openInputStream(int sharing)
Opens an input stream reading the file (read only)
|
InputStream |
openInputStream(int flags,
int access,
int sharing)
Opens an input stream reading the file (read only)
|
OutputStream |
openOutputStream()
Opens an output stream writing to the file (truncating, write only, sharable)
|
OutputStream |
openOutputStream(boolean append)
Opens an output stream writing to the file (write only, read sharable)
|
OutputStream |
openOutputStream(boolean append,
int sharing)
Opens an output stream writing to the file (write only, exclusive write access)
|
OutputStream |
openOutputStream(boolean append,
int openFlags,
int access,
int sharing)
Opens an output stream writing to the file (write only, exclusive write access)
|
SmbRandomAccess |
openRandomAccess(String mode)
Opens the file for random access
|
SmbRandomAccess |
openRandomAccess(String mode,
int sharing)
Opens the file for random access
|
void |
renameTo(SmbResource dest)
Changes the name of the file this
SmbResource represents to the name
designated by the SmbResource argument. |
void |
renameTo(SmbResource dest,
boolean replace)
Changes the name of the file this
SmbResource represents to the name
designated by the SmbResource argument. |
SmbResource |
resolve(String name)
Fetch a child resource
|
void |
setAttributes(int attrs)
Set the attributes of this file.
|
void |
setCreateTime(long time)
Set the create time of the file.
|
void |
setLastAccess(long time)
Set the last accesss time of the file.
|
void |
setLastModified(long time)
Set the last modified time of the file.
|
void |
setReadOnly()
Make this file read-only.
|
void |
setReadWrite()
Turn off the read-only attribute of this file.
|
SmbWatchHandle |
watch(int filter,
boolean recursive)
Creates a directory watch
The server will notify the client when there are changes to the directories contents
|
SmbResourceLocator getLocator()
CIFSContext getContext()
String getName()
SmbResource
or in the case of URLs that only specify a server
or workgroup, the server or workgroup will be returned. The name of
the root URL smb://
is also smb://
. If this
SmbResource refers to a workgroup, server, share, or directory,
the name will include a trailing slash '/' so that composing new
SmbResources will maintain the trailing slash requirement.smb://
if the resource is smb://
itself.int getType() throws CIFSException
CIFSException
boolean exists() throws CIFSException
SmbResource
refers to the root
smb://
resource true
is always returned. If
this SmbResource
is a traditional file or directory, it will
be queried for on the specified server as expected.true
if the resource exists or is alive or
false
otherwiseCIFSException
SmbResource resolve(String name) throws CIFSException
name
- CIFSException
long fileIndex() throws CIFSException
CIFSException
int getAttributes() throws CIFSException
CIFSException
boolean isHidden() throws CIFSException
IPC$
or C$
.true
if the SmbResource
is marked as being hiddenCIFSException
boolean isFile() throws CIFSException
SmbResource
represents is not a directory.true
if this SmbResource
is not a directoryCIFSException
boolean isDirectory() throws CIFSException
SmbResource
represents is a directory.true
if this SmbResource
is a directoryCIFSException
boolean canWrite() throws CIFSException
SmbResource
represents
exists and is not marked read-only. By default, resources are
considered to be read-only and therefore for smb://
,
smb://workgroup/
, and smb://server/
resources
will be read-only.true
if the resource exists is not marked
read-onlyCIFSException
boolean canRead() throws CIFSException
SmbResource
represents can be
read. Because any file, directory, or other resource can be read if it
exists, this method simply calls the exists
method.true
if the file is read-onlyCIFSException
void setReadWrite() throws CIFSException
CIFSException
void setReadOnly() throws CIFSException
CIFSException
void setAttributes(int attrs) throws CIFSException
attrs
- attribute flagsCIFSException
void setLastAccess(long time) throws CIFSException
time
- the last access time as milliseconds since Jan 1, 1970CIFSException
SmbUnsupportedOperationException
- if CAP_NT_SMBS is unavailablevoid setLastModified(long time) throws CIFSException
time
- the last modified time as milliseconds since Jan 1, 1970CIFSException
void setCreateTime(long time) throws CIFSException
time
- the create time as milliseconds since Jan 1, 1970CIFSException
SmbUnsupportedOperationException
- if CAP_NT_SMBS is unavailablelong lastAccess() throws CIFSException
SmbResource
long
valueCIFSException
long lastModified() throws CIFSException
SmbResource
was modified. The value returned is suitable for
constructing a Date
object (i.e. seconds since Epoch
1970). Times should be the same as those reported using the properties
dialog of the Windows Explorer program.long
valueCIFSException
long createTime() throws CIFSException
SmbResource
was created. The value
returned is suitable for constructing a Date
object
(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.long
valueCIFSException
void createNewFile() throws CIFSException
CIFSException
void mkdirs() throws CIFSException
smb://
, smb://workgroup/
,
smb://server/
, or smb://server/share/
URLs
because workgroups, servers, and shares cannot be dynamically created
(although in the future it may be possible to create shares).CIFSException
void mkdir() throws CIFSException
SmbResource
. For this method to be successful, the target
must not already exist. This method will fail when
used with smb://
, smb://workgroup/
,
smb://server/
, or smb://server/share/
URLs
because workgroups, servers, and shares cannot be dynamically created
(although in the future it may be possible to create shares).CIFSException
long getDiskFreeSpace() throws CIFSException
CIFSException
long length() throws CIFSException
SmbResource
is not a file.CIFSException
void delete() throws CIFSException
SmbResource
. 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.CIFSException
void copyTo(SmbResource dest) throws CIFSException
dest
- the destination file or directoryCIFSException
void renameTo(SmbResource dest) throws CIFSException
SmbResource
represents to the name
designated by the SmbResource
argument.
SmbResource
s are immutible and therefore
the path associated with this SmbResource
object will not
change). To access the renamed file it is necessary to construct a
new SmbResource.dest
- An SmbResource
that represents the new pathnameCIFSException
NullPointerException
- If the dest
argument is null
void renameTo(SmbResource dest, boolean replace) throws CIFSException
SmbResource
represents to the name
designated by the SmbResource
argument.
SmbResource
s are immutible and therefore
the path associated with this SmbResource
object will not
change). To access the renamed file it is necessary to construct a
new SmbResource.dest
- An SmbResource
that represents the new pathnamereplace
- Whether an existing destination file should be replaced (only supported with SMB2)CIFSException
NullPointerException
- If the dest
argument is null
SmbWatchHandle watch(int filter, boolean recursive) throws CIFSException
filter
- see constants in FileNotifyInformation
recursive
- whether to also watch subdirectoriesCIFSException
SID getOwnerGroup() throws IOException
null
if not presentIOException
SID getOwnerGroup(boolean resolve) throws IOException
resolve
- whether to resolve the group namenull
if not presentIOException
SID getOwnerUser() throws IOException
null
if not presentIOException
SID getOwnerUser(boolean resolve) throws IOException
resolve
- whether to resolve the user namenull
if not presentIOException
ACE[] getSecurity() throws IOException
Initially, the SIDs within each ACE will not be resolved however when getType(), getDomainName(), getAccountName(), or toString() 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 (usually S-X-Y-Z strings of fragments of).
Alternatively getSecurity(true) may be used to resolve all SIDs together and detect network failures.
IOException
ACE[] getSecurity(boolean resolveSids) throws IOException
resolveSids
- Attempt to resolve the SIDs within each ACE form
their numeric representation to their corresponding account names.IOException
ACE[] getShareSecurity(boolean resolveSids) throws IOException
Note that this is different from calling getSecurity on a share. There are actually two different ACLs for shares - the ACL on the share and the ACL on the folder being shared. Go to Computer Management > System Tools > Shared Folders > Shares and look at the Properties for a share. You will see two tabs - one for "Share Permissions" and another for "Security". These correspond to the ACLs returned by getShareSecurity and getSecurity respectively.
resolveSids
- Attempt to resolve the SIDs within each ACE form
their numeric representation to their corresponding account names.IOException
SmbRandomAccess openRandomAccess(String mode, int sharing) throws CIFSException
mode
- access mode (r|rw)sharing
- flags indicating for which operations others may concurrently open the fileCIFSException
SmbRandomAccess openRandomAccess(String mode) throws CIFSException
mode
- access mode (r|rw)CIFSException
OutputStream openOutputStream(boolean append, int openFlags, int access, int sharing) throws CIFSException
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 fileCIFSException
OutputStream openOutputStream(boolean append, int sharing) throws CIFSException
append
- whether to append to or truncate the inputsharing
- flags indicating for which operations others may open the file (FILE_SHARING_*)CIFSException
OutputStream openOutputStream(boolean append) throws CIFSException
append
- whether to append to or truncate the inputCIFSException
OutputStream openOutputStream() throws CIFSException
CIFSException
InputStream openInputStream(int flags, int access, int sharing) throws CIFSException
flags
- open flagsaccess
- desired access flagssharing
- flags indicating for which operations others may open the file (FILE_SHARING_*)CIFSException
InputStream openInputStream(int sharing) throws CIFSException
sharing
- flags indicating for which operations others may open the file (FILE_SHARING_*)CIFSException
InputStream openInputStream() throws CIFSException
CIFSException
void close()
close
in interface AutoCloseable
AutoCloseable.close()
CloseableIterator<SmbResource> children() throws CIFSException
CIFSException
CloseableIterator<SmbResource> children(String wildcard) throws CIFSException
The 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.
wildcard
- CIFSException
CloseableIterator<SmbResource> children(ResourceNameFilter filter) throws CIFSException
filter
- filter acting on file namesCIFSException
for a more efficient way to do this when a pattern on the filename is
sufficient for filtering
CloseableIterator<SmbResource> children(ResourceFilter filter) throws CIFSException
filter
- filter acting on SmbResource instancesCIFSException
for a more efficient way to do this when a pattern on the filename is
sufficient for filtering
Copyright © 2017. All rights reserved.