Secure iNet Factory

com.jscape.inet.sftp
Class SftpFile

java.lang.Object
  extended by com.jscape.inet.sftp.SftpFile
All Implemented Interfaces:
JFile

public class SftpFile
extends java.lang.Object
implements JFile

The SFTP file. This abstraction hides the implementation details, such as protocol commands etc., and provides full access to the remote file through the common interface.

Version:
1.0
Author:
Alex Usun

Constructor Summary
SftpFile(SftpFile parent, java.lang.String child, SftpClient client)
          Creates a new SFTP file instance from a parent abstract pathname and a child pathname string.
SftpFile(java.lang.String path, SftpClient client)
          Creates a new SFTP file instance by converting the given path string into an abstract path.
 
Method Summary
 void createNewDirectory()
          Creates the directory named by this abstract pathname if and only if a file with this name does not yet exist.
 void createNewFile()
          Creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
 void createNewLink(JFile target)
          Creates the symbolic link named by this abstract pathname if and only if a file with this name does not yet exist.
 void delete()
          Deletes the file or directory denoted by this abstract pathname.
 void deleteRecursive()
          Recursively deletes the file or directory denoted by this abstract pathname.
 boolean exists()
          Tests whether the file denoted by this abstract pathname exists.
 long getAccessTime()
          Returns the file access time as seconds from Jan 1, 1970 in UTC.
 long getAccessTimeNsec()
          Returns the additional file access time nano-seconds.
 JAcl[] getAcl()
          Obtains the file ACL array similar to that defined in section 5.9 of NFS version 4 Protocol
 long getCreationTime()
          Returns the file creation time as seconds from Jan 1, 1970 in UTC.
 long getCreationTimeNsec()
          Returns the additional file creation time nano-seconds.
 java.util.Date getDate()
          Returns the file modification date as Data object.
 java.lang.String getFilename()
          Returns the name of the file or directory denoted by this abstract pathname.
 long getFilesize()
          Returns the size of the file denoted by this abstract pathname.
 JFileSystem getFileSystem()
          Returns the underlayed file system object.
 java.lang.String getGroup()
          Returns the owner group name for this abstract pathname as string.
 JFile getLinkTarget()
          Returns the link target if the current file is symbolic link.
 long getModificationTime()
          Returns the file modification time as seconds from Jan 1, 1970 in UTC.
 long getModificationTimeNsec()
          Returns the additional file modification time nano-seconds.
 java.lang.String getOwner()
          Returns the owner name for this abstract pathname as string.
 JFile getParentFile()
          Returns the abstract pathname of this abstract pathname's parent.
 java.lang.String getPath()
          Converts this abstract pathname into a pathname string.
 java.lang.String getPermission()
          Returns POSIX string representation of the file permissions.
 JFilePermissions getPermissions()
          Returns the POSIX file permissions for this abstract pathname.
 JRandomAccessFile getRandomAccessFile(JFileOpenFlags openFlags, JAcl.Mask accessType)
          Provides access to the file contents returning a new JRandomAccessFile instance.
 java.lang.String getTime()
          Returns the file modification time as String.
 JFileType getType()
          Returns the POSIX file type represented by this abstract pathname.
 boolean isAppendOnly()
          Tests whether the file named by this abstract pathname can only be opened for writing in append mode.
 boolean isArchive()
          Tests whether the file named by this abstract pathname should be included in backup / archive operations.
 boolean isCaseInsensitive()
          This attribute can only apply to directories.
 boolean isCompressed()
          Tests whether the file named by this abstract pathname is compressed.
 boolean isDirectory()
          Tests whether the file denoted by this abstract pathname is a directory.
 boolean isEncrypted()
          Tests whether the file named by this abstract pathname is encrypted.
 boolean isHidden()
          Tests whether the file named by this abstract pathname is a hidden file.
 boolean isImmutable()
          Tests whether the file named by this abstract pathname cannot be deleted or renamed, no hard link can be created to this file and no data can be written to the file.
 boolean isReadOnly()
          Tests whether the file named by this abstract pathname is not writable.
 boolean isSparse()
          Tests whether the file named by this abstract pathname is sparse.
 boolean isSync()
          Tests whether the file named by this abstract pathname when is modified, the changes are written synchronously to the disk.
 boolean isSystem()
          Tests whether the file named by this abstract pathname is part of operating system.
 JFile[] listFiles()
          Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
 JFile[] listFiles(JFileFilter filter)
          Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
 void renameTo(JFile dest)
          Renames the file denoted by this abstract pathname.
 void setAcl(JAcl[] acls)
          Setups the file ACL's.
 void setArchive(boolean archive)
          Setups archive attribute for this file.
 void setGroup(java.lang.String gid)
          Setups the new file owner group ID.
 void setImmutable(boolean immutable)
          Setups file immutability.
 void setOwner(java.lang.String uid)
          Setups the new file user ID.
 void setPermissions(JFilePermissions permissions)
          Setups the new file permissions.
 void setSync(boolean sync)
          Setups file changes synchronization mode.
 java.lang.String toString()
          Obtains the current file string representation in for as Unix "ls -l" command does, i.e.: "-rw-rw-rw- owner group 23412 Oct 10 2004 10:20 somefile.txt"
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SftpFile

public SftpFile(java.lang.String path,
                SftpClient client)
Creates a new SFTP file instance by converting the given path string into an abstract path.

Parameters:
path - a path string
client - the underlayed SFTP client

SftpFile

public SftpFile(SftpFile parent,
                java.lang.String child,
                SftpClient client)
Creates a new SFTP file instance from a parent abstract pathname and a child pathname string.

Parameters:
parent - the parent abstract pathname
child - the child pathname string
client - the underlayed SFTP client
Method Detail

getFilename

public java.lang.String getFilename()
Returns the name of the file or directory denoted by this abstract pathname.

Specified by:
getFilename in interface JFile
Returns:
the name of the file or directory denoted by this abstract pathname

getPath

public java.lang.String getPath()
Converts this abstract pathname into a pathname string.

Specified by:
getPath in interface JFile
Returns:
the string form of this abstract pathname

getParentFile

public JFile getParentFile()
Returns the abstract pathname of this abstract pathname's parent.

Specified by:
getParentFile in interface JFile
Returns:
the abstract pathname of the parent directory named by this abstract pathname

getType

public JFileType getType()
                  throws SftpException
Returns the POSIX file type represented by this abstract pathname.

Specified by:
getType in interface JFile
Returns:
the POSIX file type represented by this abstract pathname
Throws:
SftpException - if an I/O error occured

isDirectory

public boolean isDirectory()
                    throws SftpException
Tests whether the file denoted by this abstract pathname is a directory.

Specified by:
isDirectory in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
Throws:
SftpException - if an I/O error occured

getFilesize

public long getFilesize()
                 throws SftpException
Returns the size of the file denoted by this abstract pathname.

Specified by:
getFilesize in interface JFile
Returns:
the size, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
Throws:
SftpException - if an I/O error occured

getOwner

public java.lang.String getOwner()
                          throws SftpException
Returns the owner name for this abstract pathname as string.

Specified by:
getOwner in interface JFile
Returns:
the owner name for this abstract pathname as string
Throws:
SftpException - if an I/O error occured

setOwner

public void setOwner(java.lang.String uid)
              throws SftpException
Setups the new file user ID.

Specified by:
setOwner in interface JFile
Parameters:
uid - the new file user ID
Throws:
SftpException - if an I/O error occured

getGroup

public java.lang.String getGroup()
                          throws SftpException
Returns the owner group name for this abstract pathname as string.

Specified by:
getGroup in interface JFile
Returns:
the owner gropu name for this abstract pathname as string
Throws:
SftpException - if an I/O error occured

setGroup

public void setGroup(java.lang.String gid)
              throws SftpException
Setups the new file owner group ID.

Specified by:
setGroup in interface JFile
Parameters:
gid - the new file owner group ID
Throws:
SftpException - if an I/O error occured

getPermissions

public JFilePermissions getPermissions()
                                throws SftpException
Returns the POSIX file permissions for this abstract pathname.

Specified by:
getPermissions in interface JFile
Returns:
the POSIX file permissions for this abstract pathname
Throws:
SftpException - if an I/O error occured

getPermission

public java.lang.String getPermission()
                               throws SftpException
Returns POSIX string representation of the file permissions. Legacy method from the FtpFile.

Returns:
POSIX string representation of the file permissions
Throws:
SftpException - if an I/O error occured

setPermissions

public void setPermissions(JFilePermissions permissions)
                    throws SftpException
Setups the new file permissions.

Specified by:
setPermissions in interface JFile
Parameters:
permissions - the new file permissions
Throws:
SftpException - if an I/O error occured

getAccessTime

public long getAccessTime()
                   throws SftpException
Returns the file access time as seconds from Jan 1, 1970 in UTC. A negative value indicates number of seconds before Jan 1, 1970.

Specified by:
getAccessTime in interface JFile
Returns:
the file access time in seconds
Throws:
SftpException - if an I/O error occured

getAccessTimeNsec

public long getAccessTimeNsec()
                       throws SftpException
Returns the additional file access time nano-seconds.

Specified by:
getAccessTimeNsec in interface JFile
Returns:
the additional file access time nano-seconds
Throws:
SftpException - if an I/O error occured

getCreationTime

public long getCreationTime()
                     throws SftpException
Returns the file creation time as seconds from Jan 1, 1970 in UTC. A negative value indicates number of seconds before Jan 1, 1970.

Specified by:
getCreationTime in interface JFile
Returns:
the file creation time in seconds
Throws:
SftpException - if an I/O error occured

getCreationTimeNsec

public long getCreationTimeNsec()
                         throws SftpException
Returns the additional file creation time nano-seconds.

Specified by:
getCreationTimeNsec in interface JFile
Returns:
the additional file creation time nano-seconds
Throws:
SftpException

getModificationTime

public long getModificationTime()
                         throws SftpException
Returns the file modification time as seconds from Jan 1, 1970 in UTC. A negative value indicates number of seconds before Jan 1, 1970.

Specified by:
getModificationTime in interface JFile
Returns:
the file modification time in seconds
Throws:
SftpException - if an I/O error occured

getModificationTimeNsec

public long getModificationTimeNsec()
                             throws SftpException
Returns the additional file modification time nano-seconds.

Specified by:
getModificationTimeNsec in interface JFile
Returns:
the additional file modification time nano-seconds
Throws:
SftpException

getDate

public java.util.Date getDate()
                       throws SftpException
Returns the file modification date as Data object. Legacy code from the FtpFile.

Returns:
the file modification date
Throws:
SftpException - if an I/O error occured

getTime

public java.lang.String getTime()
                         throws SftpException
Returns the file modification time as String. Legacy method from the FtpFile.

Returns:
the file modification time as String
Throws:
SftpException - if an I/O error occured

getAcl

public JAcl[] getAcl()
              throws SftpException
Obtains the file ACL array similar to that defined in section 5.9 of NFS version 4 Protocol

Specified by:
getAcl in interface JFile
Returns:
the file ACL array
Throws:
SftpException - if an I/O error occured

setAcl

public void setAcl(JAcl[] acls)
            throws SftpException
Setups the file ACL's.

Specified by:
setAcl in interface JFile
Parameters:
acls - the new file ACL's
Throws:
SftpException - if an I/O error occured

isReadOnly

public boolean isReadOnly()
                   throws SftpException
Tests whether the file named by this abstract pathname is not writable.

Specified by:
isReadOnly in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is not writable; false otherwise
Throws:
SftpException - if an I/O error occured

isSystem

public boolean isSystem()
                 throws SftpException
Tests whether the file named by this abstract pathname is part of operating system.

Specified by:
isSystem in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is part of operation system; false otherwise
Throws:
SftpException - if an I/O error occured

isHidden

public boolean isHidden()
                 throws SftpException
Tests whether the file named by this abstract pathname is a hidden file.

Specified by:
isHidden in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is hidden according to the conventions of the underlying platform; false otherwise
Throws:
SftpException - if an I/O error occured

isCaseInsensitive

public boolean isCaseInsensitive()
                          throws SftpException
This attribute can only apply to directories. It means that files and directory names in this directory should be compared without regard to case.

Specified by:
isCaseInsensitive in interface JFile
Returns:
true if and only if files and directory names in this directory should be compared without regard to case; false otherwise
Throws:
SftpException - if an I/O error occured

isArchive

public boolean isArchive()
                  throws SftpException
Tests whether the file named by this abstract pathname should be included in backup / archive operations.

Specified by:
isArchive in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname should be included in backup / archive operations; false otherwise
Throws:
SftpException - if an I/O error occured

setArchive

public void setArchive(boolean archive)
                throws SftpException
Setups archive attribute for this file.

Specified by:
setArchive in interface JFile
Parameters:
archive - if true the file denoted by this abstract pathname should be included in backup / archive operations
Throws:
SftpException - if an I/O error occured

isEncrypted

public boolean isEncrypted()
                    throws SftpException
Tests whether the file named by this abstract pathname is encrypted.

Specified by:
isEncrypted in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is encrypted; false otherwise
Throws:
SftpException - if an I/O error occured

isCompressed

public boolean isCompressed()
                     throws SftpException
Tests whether the file named by this abstract pathname is compressed.

Specified by:
isCompressed in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is compressed; false otherwise
Throws:
SftpException - if an I/O error occured

isSparse

public boolean isSparse()
                 throws SftpException
Tests whether the file named by this abstract pathname is sparse. This means that file blocks that have not been explicitly written are not stored on disk. For example, if a client writes a buffer at 10 Mb from the beginning of the file, the blocks between the previous EOF marker and the 10 Mb offset would not consume physical disk space. Some systems may store all files as sparse files, in which case this attribute will be unconditionally set. Other systems may not have a mechanism for determining if the file is sparse, and so the file MAY be stored sparse even if this flag is not set.

Specified by:
isSparse in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is sparse; false otherwise
Throws:
SftpException - if an I/O error occured

isAppendOnly

public boolean isAppendOnly()
                     throws SftpException
Tests whether the file named by this abstract pathname can only be opened for writing in append mode.

Specified by:
isAppendOnly in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname can only be opened for writing in append mode; false otherwise
Throws:
SftpException - if an I/O error occured

isImmutable

public boolean isImmutable()
                    throws SftpException
Tests whether the file named by this abstract pathname cannot be deleted or renamed, no hard link can be created to this file and no data can be written to the file.

Specified by:
isImmutable in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is immutable; false otherwise
Throws:
SftpException - if an I/O error occured

setImmutable

public void setImmutable(boolean immutable)
                  throws SftpException
Setups file immutability. Typically only the superuser can set or remove this attribute.

Specified by:
setImmutable in interface JFile
Parameters:
immutable - if true the file becames immutable
Throws:
SftpException - if an I/O error occured

isSync

public boolean isSync()
               throws SftpException
Tests whether the file named by this abstract pathname when is modified, the changes are written synchronously to the disk.

Specified by:
isSync in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname is sync; false otherwise
Throws:
SftpException - if an I/O error occured

setSync

public void setSync(boolean sync)
             throws SftpException
Setups file changes synchronization mode.

Specified by:
setSync in interface JFile
Parameters:
sync - if true the changes to this file must be written synchronously to the disk
Throws:
SftpException - if an I/O error occured

exists

public boolean exists()
               throws SftpException
Tests whether the file denoted by this abstract pathname exists.

Specified by:
exists in interface JFile
Returns:
true if and only if the file denoted by this abstract pathname exists; false otherwise
Throws:
SftpException

createNewFile

public void createNewFile()
                   throws SftpException
Creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.

Specified by:
createNewFile in interface JFile
Throws:
SftpException - if an I/O error occurred

createNewDirectory

public void createNewDirectory()
                        throws SftpException
Creates the directory named by this abstract pathname if and only if a file with this name does not yet exist.

Specified by:
createNewDirectory in interface JFile
Throws:
SftpException - if an I/O error occurred

createNewLink

public void createNewLink(JFile target)
                   throws SftpException
Creates the symbolic link named by this abstract pathname if and only if a file with this name does not yet exist.

Specified by:
createNewLink in interface JFile
Parameters:
target - target file for the link
Throws:
SftpException - if an I/O error occurred

renameTo

public void renameTo(JFile dest)
              throws SftpException
Renames the file denoted by this abstract pathname.

Specified by:
renameTo in interface JFile
Parameters:
dest - the new abstract pathname for the named file
Throws:
SftpException - if an I/O error occurred

delete

public void delete()
            throws SftpException
Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.

Specified by:
delete in interface JFile
Throws:
SftpException - if an I/O error occurred

deleteRecursive

public void deleteRecursive()
                     throws SftpException
Recursively deletes the file or directory denoted by this abstract pathname.

Specified by:
deleteRecursive in interface JFile
Throws:
SftpException - if an I/O error occurred

listFiles

public JFile[] listFiles()
                  throws SftpException
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

Specified by:
listFiles in interface JFile
Returns:
an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty.
Throws:
SftpException - if an I/O error occurred

listFiles

public JFile[] listFiles(JFileFilter filter)
                  throws SftpException
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

Specified by:
listFiles in interface JFile
Parameters:
filter - a file filter
Returns:
an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty.
Throws:
SftpException - if an I/O error occurred

getLinkTarget

public JFile getLinkTarget()
                    throws SftpException
Returns the link target if the current file is symbolic link.

Specified by:
getLinkTarget in interface JFile
Returns:
the link target
Throws:
SftpException - if an I/O error occured

getRandomAccessFile

public JRandomAccessFile getRandomAccessFile(JFileOpenFlags openFlags,
                                             JAcl.Mask accessType)
                                      throws SftpException
Provides access to the file contents returning a new JRandomAccessFile instance.

Specified by:
getRandomAccessFile in interface JFile
Parameters:
openFlags - the file open flags
accessType - desired access type
Returns:
a new JRandomAccessFile instance
Throws:
SftpException - if an I/O error occurred

getFileSystem

public JFileSystem getFileSystem()
Returns the underlayed file system object.

Specified by:
getFileSystem in interface JFile
Returns:
the underlayed file system object

toString

public java.lang.String toString()
Obtains the current file string representation in for as Unix "ls -l" command does, i.e.: "-rw-rw-rw- owner group 23412 Oct 10 2004 10:20 somefile.txt"

Overrides:
toString in class java.lang.Object
Returns:
the current file string representation

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved