KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > io > FileSystem


1 /*
2  * @(#)FileSystem.java 1.13 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.io;
9
10
11 /**
12  * Package-private abstract class for the local filesystem abstraction.
13  */

14
15 abstract class FileSystem {
16
17     /**
18      * Return the FileSystem object representing this platform's local
19      * filesystem.
20      */

21     public static native FileSystem JavaDoc getFileSystem();
22
23
24     /* -- Normalization and construction -- */
25
26     /**
27      * Return the local filesystem's name-separator character.
28      */

29     public abstract char getSeparator();
30
31     /**
32      * Return the local filesystem's path-separator character.
33      */

34     public abstract char getPathSeparator();
35
36     /**
37      * Convert the given pathname string to normal form. If the string is
38      * already in normal form then it is simply returned.
39      */

40     public abstract String JavaDoc normalize(String JavaDoc path);
41
42     /**
43      * Compute the length of this pathname string's prefix. The pathname
44      * string must be in normal form.
45      */

46     public abstract int prefixLength(String JavaDoc path);
47
48     /**
49      * Resolve the child pathname string against the parent.
50      * Both strings must be in normal form, and the result
51      * will be in normal form.
52      */

53     public abstract String JavaDoc resolve(String JavaDoc parent, String JavaDoc child);
54
55     /**
56      * Return the parent pathname string to be used when the parent-directory
57      * argument in one of the two-argument File constructors is the empty
58      * pathname.
59      */

60     public abstract String JavaDoc getDefaultParent();
61
62     /**
63      * Post-process the given URI path string if necessary. This is used on
64      * win32, e.g., to transform "/c:/foo" into "c:/foo". The path string
65      * still has slash separators; code in the File class will translate them
66      * after this method returns.
67      */

68     public abstract String JavaDoc fromURIPath(String JavaDoc path);
69
70
71     /* -- Path operations -- */
72
73     /**
74      * Tell whether or not the given abstract pathname is absolute.
75      */

76     public abstract boolean isAbsolute(File JavaDoc f);
77
78     /**
79      * Resolve the given abstract pathname into absolute form. Invoked by the
80      * getAbsolutePath and getCanonicalPath methods in the File class.
81      */

82     public abstract String JavaDoc resolve(File JavaDoc f);
83
84     public abstract String JavaDoc canonicalize(String JavaDoc path) throws IOException JavaDoc;
85
86
87     /* -- Attribute accessors -- */
88
89     /* Constants for simple boolean attributes */
90     public static final int BA_EXISTS = 0x01;
91     public static final int BA_REGULAR = 0x02;
92     public static final int BA_DIRECTORY = 0x04;
93     public static final int BA_HIDDEN = 0x08;
94
95     /**
96      * Return the simple boolean attributes for the file or directory denoted
97      * by the given abstract pathname, or zero if it does not exist or some
98      * other I/O error occurs.
99      */

100     public abstract int getBooleanAttributes(File JavaDoc f);
101
102     /**
103      * Check whether the file or directory denoted by the given abstract
104      * pathname may be accessed by this process. If the second argument is
105      * <code>false</code>, then a check for read access is made; if the second
106      * argument is <code>true</code>, then a check for write (not read-write)
107      * access is made. Return false if access is denied or an I/O error
108      * occurs.
109      */

110     public abstract boolean checkAccess(File JavaDoc f, boolean write);
111
112     /**
113      * Return the time at which the file or directory denoted by the given
114      * abstract pathname was last modified, or zero if it does not exist or
115      * some other I/O error occurs.
116      */

117     public abstract long getLastModifiedTime(File JavaDoc f);
118
119     /**
120      * Return the length in bytes of the file denoted by the given abstract
121      * pathname, or zero if it does not exist, is a directory, or some other
122      * I/O error occurs.
123      */

124     public abstract long getLength(File JavaDoc f);
125
126
127     /* -- File operations -- */
128
129     /**
130      * Create a new empty file with the given pathname. Return
131      * <code>true</code> if the file was created and <code>false</code> if a
132      * file or directory with the given pathname already exists. Throw an
133      * IOException if an I/O error occurs.
134      */

135     public abstract boolean createFileExclusively(String JavaDoc pathname)
136     throws IOException JavaDoc;
137
138     /**
139      * Delete the file or directory denoted by the given abstract pathname,
140      * returning <code>true</code> if and only if the operation succeeds.
141      */

142     public abstract boolean delete(File JavaDoc f);
143
144     /**
145      * Arrange for the file or directory denoted by the given abstract
146      * pathname to be deleted when the VM exits, returning <code>true</code> if
147      * and only if the operation succeeds.
148      */

149     public abstract boolean deleteOnExit(File JavaDoc f);
150
151     /**
152      * List the elements of the directory denoted by the given abstract
153      * pathname. Return an array of strings naming the elements of the
154      * directory if successful; otherwise, return <code>null</code>.
155      */

156     public abstract String JavaDoc[] list(File JavaDoc f);
157
158     /**
159      * Create a new directory denoted by the given abstract pathname,
160      * returning <code>true</code> if and only if the operation succeeds.
161      */

162     public abstract boolean createDirectory(File JavaDoc f);
163
164     /**
165      * Rename the file or directory denoted by the first abstract pathname to
166      * the second abstract pathname, returning <code>true</code> if and only if
167      * the operation succeeds.
168      */

169     public abstract boolean rename(File JavaDoc f1, File JavaDoc f2);
170
171     /**
172      * Set the last-modified time of the file or directory denoted by the
173      * given abstract pathname, returning <code>true</code> if and only if the
174      * operation succeeds.
175      */

176     public abstract boolean setLastModifiedTime(File JavaDoc f, long time);
177
178     /**
179      * Mark the file or directory denoted by the given abstract pathname as
180      * read-only, returning <code>true</code> if and only if the operation
181      * succeeds.
182      */

183     public abstract boolean setReadOnly(File JavaDoc f);
184
185
186     /* -- Filesystem interface -- */
187
188     /**
189      * List the available filesystem roots.
190      */

191     public abstract File JavaDoc[] listRoots();
192
193
194     /* -- Basic infrastructure -- */
195
196     /**
197      * Compare two abstract pathnames lexicographically.
198      */

199     public abstract int compare(File JavaDoc f1, File JavaDoc f2);
200
201     /**
202      * Compute the hash code of an abstract pathname.
203      */

204     public abstract int hashCode(File JavaDoc f);
205
206     // Flags for enabling/disabling performance optimizations for file
207
// name canonicalization
208
static boolean useCanonCaches = true;
209     static boolean useCanonPrefixCache = true;
210
211     private static boolean getBooleanProperty(String JavaDoc prop, boolean defaultVal) {
212         String JavaDoc val = System.getProperty(prop);
213         if (val == null) return defaultVal;
214         if (val.equalsIgnoreCase("true")) {
215             return true;
216         } else {
217             return false;
218         }
219     }
220
221     static {
222         useCanonCaches = getBooleanProperty("sun.io.useCanonCaches",
223                                                  useCanonCaches);
224         useCanonPrefixCache = getBooleanProperty("sun.io.useCanonPrefixCache",
225                                                  useCanonPrefixCache);
226     }
227 }
228
Popular Tags