79 return sb.toString();
80 }
81
82 /* Check that the given pathname is normal. If not, invoke the real
83 normalizer on the part of the pathname that requires normalization.
84 This way we iterate through the whole pathname string only once. */
85 public String normalize(String pathname) {
86 int n = pathname.length();
87 char prevChar = 0;
88 for (int i = 0; i < n; i++) {
89 char c = pathname.charAt(i);
90 if ((prevChar == '/') && (c == '/'))
91 return normalize(pathname, n, i - 1);
92 prevChar = c;
93 }
94 if (prevChar == '/') return normalize(pathname, n, n - 1);
95 return pathname;
96 }
97
98 public int prefixLength(String pathname) {
99 if (pathname.length() == 0) return 0;
100 return (pathname.charAt(0) == '/') ? 1 : 0;
101 }
102
103 public String resolve(String parent, String child) {
104 if (child.equals("")) return parent;
105 if (child.charAt(0) == '/') {
106 if (parent.equals("/")) return child;
107 return parent + child;
108 }
109 if (parent.equals("/")) return parent + child;
110 return parent + '/' + child;
111 }
112
113 public String getDefaultParent() {
114 return "/";
115 }
116
117 public String fromURIPath(String path) {
118 String p = path;
119 if (p.endsWith("/") && (p.length() > 1)) {
230 // toward the end
231 return null;
232 }
233 return path.substring(0, idx);
234 } else {
235 ++nonDotCount;
236 adjacentDots = 0;
237 }
238 --idx;
239 }
240 return null;
241 }
242
243 /* -- Attribute accessors -- */
244
245 public native int getBooleanAttributes0(File f);
246
247 public int getBooleanAttributes(File f) {
248 int rv = getBooleanAttributes0(f);
249 String name = f.getName();
250 boolean hidden = (name.length() > 0) && (name.charAt(0) == '.');
251 return rv | (hidden ? BA_HIDDEN : 0);
252 }
253
254 public native boolean checkAccess(File f, int access);
255 public native long getLastModifiedTime(File f);
256 public native long getLength(File f);
257 public native boolean setPermission(File f, int access, boolean enable, boolean owneronly);
258
259 /* -- File operations -- */
260
261 public native boolean createFileExclusively(String path)
262 throws IOException;
263 public boolean delete(File f) {
264 // Keep canonicalization caches in sync after file deletion
265 // and renaming operations. Could be more clever than this
266 // (i.e., only remove/update affected entries) but probably
267 // not worth it since these entries expire after 30 seconds
268 // anyway.
269 cache.clear();
270 javaHomePrefixCache.clear();
|
79 return sb.toString();
80 }
81
82 /* Check that the given pathname is normal. If not, invoke the real
83 normalizer on the part of the pathname that requires normalization.
84 This way we iterate through the whole pathname string only once. */
85 public String normalize(String pathname) {
86 int n = pathname.length();
87 char prevChar = 0;
88 for (int i = 0; i < n; i++) {
89 char c = pathname.charAt(i);
90 if ((prevChar == '/') && (c == '/'))
91 return normalize(pathname, n, i - 1);
92 prevChar = c;
93 }
94 if (prevChar == '/') return normalize(pathname, n, n - 1);
95 return pathname;
96 }
97
98 public int prefixLength(String pathname) {
99 if (pathname.isEmpty()) return 0;
100 return (pathname.charAt(0) == '/') ? 1 : 0;
101 }
102
103 public String resolve(String parent, String child) {
104 if (child.equals("")) return parent;
105 if (child.charAt(0) == '/') {
106 if (parent.equals("/")) return child;
107 return parent + child;
108 }
109 if (parent.equals("/")) return parent + child;
110 return parent + '/' + child;
111 }
112
113 public String getDefaultParent() {
114 return "/";
115 }
116
117 public String fromURIPath(String path) {
118 String p = path;
119 if (p.endsWith("/") && (p.length() > 1)) {
230 // toward the end
231 return null;
232 }
233 return path.substring(0, idx);
234 } else {
235 ++nonDotCount;
236 adjacentDots = 0;
237 }
238 --idx;
239 }
240 return null;
241 }
242
243 /* -- Attribute accessors -- */
244
245 public native int getBooleanAttributes0(File f);
246
247 public int getBooleanAttributes(File f) {
248 int rv = getBooleanAttributes0(f);
249 String name = f.getName();
250 boolean hidden = !name.isEmpty() && name.charAt(0) == '.';
251 return rv | (hidden ? BA_HIDDEN : 0);
252 }
253
254 public native boolean checkAccess(File f, int access);
255 public native long getLastModifiedTime(File f);
256 public native long getLength(File f);
257 public native boolean setPermission(File f, int access, boolean enable, boolean owneronly);
258
259 /* -- File operations -- */
260
261 public native boolean createFileExclusively(String path)
262 throws IOException;
263 public boolean delete(File f) {
264 // Keep canonicalization caches in sync after file deletion
265 // and renaming operations. Could be more clever than this
266 // (i.e., only remove/update affected entries) but probably
267 // not worth it since these entries expire after 30 seconds
268 // anyway.
269 cache.clear();
270 javaHomePrefixCache.clear();
|