KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > ssh2 > SFTPv3FileAttributes


1
2 package ch.ethz.ssh2;
3
4 /**
5  * A <code>SFTPv3FileAttributes</code> object represents detail information
6  * about a file on the server. Not all fields may/must be present.
7  *
8  * @author Christian Plattner, plattner@inf.ethz.ch
9  * @version $Id: SFTPv3FileAttributes.java,v 1.3 2006/09/04 07:41:46 cplattne Exp $
10  */

11
12 public class SFTPv3FileAttributes
13 {
14     /**
15      * The SIZE attribute. <code>NULL</code> if not present.
16      */

17     public Long JavaDoc size = null;
18
19     /**
20      * The UID attribute. <code>NULL</code> if not present.
21      */

22     public Integer JavaDoc uid = null;
23
24     /**
25      * The GID attribute. <code>NULL</code> if not present.
26      */

27     public Integer JavaDoc gid = null;
28
29     /**
30      * The POSIX permissions. <code>NULL</code> if not present.
31      * <p>
32      * Here is a list:
33      * <p>
34      * <pre>Note: these numbers are all OCTAL.
35      *
36      * S_IFMT 0170000 bitmask for the file type bitfields
37      * S_IFSOCK 0140000 socket
38      * S_IFLNK 0120000 symbolic link
39      * S_IFREG 0100000 regular file
40      * S_IFBLK 0060000 block device
41      * S_IFDIR 0040000 directory
42      * S_IFCHR 0020000 character device
43      * S_IFIFO 0010000 fifo
44      * S_ISUID 0004000 set UID bit
45      * S_ISGID 0002000 set GID bit
46      * S_ISVTX 0001000 sticky bit
47      *
48      * S_IRWXU 00700 mask for file owner permissions
49      * S_IRUSR 00400 owner has read permission
50      * S_IWUSR 00200 owner has write permission
51      * S_IXUSR 00100 owner has execute permission
52      * S_IRWXG 00070 mask for group permissions
53      * S_IRGRP 00040 group has read permission
54      * S_IWGRP 00020 group has write permission
55      * S_IXGRP 00010 group has execute permission
56      * S_IRWXO 00007 mask for permissions for others (not in group)
57      * S_IROTH 00004 others have read permission
58      * S_IWOTH 00002 others have write permisson
59      * S_IXOTH 00001 others have execute permission
60      * </pre>
61      */

62     public Integer JavaDoc permissions = null;
63
64     /**
65      * The ATIME attribute. Represented as seconds from Jan 1, 1970 in UTC.
66      * <code>NULL</code> if not present.
67      */

68     public Integer JavaDoc atime = null;
69
70     /**
71      * The MTIME attribute. Represented as seconds from Jan 1, 1970 in UTC.
72      * <code>NULL</code> if not present.
73      */

74     public Integer JavaDoc mtime = null;
75
76     /**
77      * Checks if this entry is a directory.
78      *
79      * @return Returns true if permissions are available and they indicate
80      * that this entry represents a directory.
81      */

82     public boolean isDirectory()
83     {
84         if (permissions == null)
85             return false;
86         
87         return ((permissions.intValue() & 0040000) != 0);
88     }
89     
90     /**
91      * Checks if this entry is a regular file.
92      *
93      * @return Returns true if permissions are available and they indicate
94      * that this entry represents a regular file.
95      */

96     public boolean isRegularFile()
97     {
98         if (permissions == null)
99             return false;
100         
101         return ((permissions.intValue() & 0100000) != 0);
102     }
103     
104     /**
105      * Checks if this entry is a a symlink.
106      *
107      * @return Returns true if permissions are available and they indicate
108      * that this entry represents a symlink.
109      */

110     public boolean isSymlink()
111     {
112         if (permissions == null)
113             return false;
114         
115         return ((permissions.intValue() & 0120000) != 0);
116     }
117     
118     /**
119      * Turn the POSIX permissions into a 7 digit octal representation.
120      * Note: the returned value is first masked with <code>0177777</code>.
121      *
122      * @return <code>NULL</code> if permissions are not available.
123      */

124     public String JavaDoc getOctalPermissions()
125     {
126         if (permissions == null)
127             return null;
128
129         String JavaDoc res = Integer.toString(permissions.intValue() & 0177777, 8);
130
131         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
132
133         int leadingZeros = 7 - res.length();
134
135         while (leadingZeros > 0)
136         {
137             sb.append('0');
138             leadingZeros--;
139         }
140
141         sb.append(res);
142
143         return sb.toString();
144     }
145 }
146
Popular Tags