| Method from java.io.UnixFileSystem Detail: |
public String canonicalize(String path) throws IOException {
if (!useCanonCaches) {
return canonicalize0(path);
} else {
String res = cache.get(path);
if (res == null) {
String dir = null;
String resDir = null;
if (useCanonPrefixCache) {
// Note that this can cause symlinks that should
// be resolved to a destination directory to be
// resolved to the directory they're contained in
dir = parentOrNull(path);
if (dir != null) {
resDir = javaHomePrefixCache.get(dir);
if (resDir != null) {
// Hit only in prefix cache; full path is canonical
String filename = path.substring(1 + dir.length());
res = resDir + slash + filename;
cache.put(dir + slash + filename, res);
}
}
}
if (res == null) {
res = canonicalize0(path);
cache.put(path, res);
if (useCanonPrefixCache &&
dir != null && dir.startsWith(javaHome)) {
resDir = parentOrNull(res);
// Note that we don't allow a resolved symlink
// to elsewhere in java.home to pollute the
// prefix cache (java.home prefix cache could
// just as easily be a set at this point)
if (resDir != null && resDir.equals(dir)) {
File f = new File(res);
if (f.exists() && !f.isDirectory()) {
javaHomePrefixCache.put(dir, resDir);
}
}
}
}
}
assert canonicalize0(path).equals(res) || path.startsWith(javaHome);
return res;
}
}
|
public native boolean checkAccess(File f,
int access)
|
public int compare(File f1,
File f2) {
return f1.getPath().compareTo(f2.getPath());
}
|
public native boolean createDirectory(File f)
|
public native boolean createFileExclusively(String path) throws IOException
|
public boolean delete(File f) {
// Keep canonicalization caches in sync after file deletion
// and renaming operations. Could be more clever than this
// (i.e., only remove/update affected entries) but probably
// not worth it since these entries expire after 30 seconds
// anyway.
cache.clear();
javaHomePrefixCache.clear();
return delete0(f);
}
|
public String fromURIPath(String path) {
String p = path;
if (p.endsWith("/") && (p.length() > 1)) {
// "/foo/" -- > "/foo", but "/" -- > "/"
p = p.substring(0, p.length() - 1);
}
return p;
}
|
public int getBooleanAttributes(File f) {
int rv = getBooleanAttributes0(f);
String name = f.getName();
boolean hidden = (name.length() > 0) && (name.charAt(0) == '.");
return rv | (hidden ? BA_HIDDEN : 0);
}
|
public native int getBooleanAttributes0(File f)
|
public String getDefaultParent() {
return "/";
}
|
public native long getLastModifiedTime(File f)
|
public native long getLength(File f)
|
public char getPathSeparator() {
return colon;
}
|
public char getSeparator() {
return slash;
}
|
public native long getSpace(File f,
int t)
|
public int hashCode(File f) {
return f.getPath().hashCode() ^ 1234321;
}
|
public boolean isAbsolute(File f) {
return (f.getPrefixLength() != 0);
}
|
public native String[] list(File f)
|
public File[] listRoots() {
try {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead("/");
}
return new File[] { new File("/") };
} catch (SecurityException x) {
return new File[0];
}
}
|
public String normalize(String pathname) {
int n = pathname.length();
char prevChar = 0;
for (int i = 0; i < n; i++) {
char c = pathname.charAt(i);
if ((prevChar == '/") && (c == '/"))
return normalize(pathname, n, i - 1);
prevChar = c;
}
if (prevChar == '/") return normalize(pathname, n, n - 1);
return pathname;
}
|
static String parentOrNull(String path) {
if (path == null) return null;
char sep = File.separatorChar;
int last = path.length() - 1;
int idx = last;
int adjacentDots = 0;
int nonDotCount = 0;
while (idx > 0) {
char c = path.charAt(idx);
if (c == '.") {
if (++adjacentDots >= 2) {
// Punt on pathnames containing . and ..
return null;
}
} else if (c == sep) {
if (adjacentDots == 1 && nonDotCount == 0) {
// Punt on pathnames containing . and ..
return null;
}
if (idx == 0 ||
idx >= last - 1 ||
path.charAt(idx - 1) == sep) {
// Punt on pathnames containing adjacent slashes
// toward the end
return null;
}
return path.substring(0, idx);
} else {
++nonDotCount;
adjacentDots = 0;
}
--idx;
}
return null;
}
|
public int prefixLength(String pathname) {
if (pathname.length() == 0) return 0;
return (pathname.charAt(0) == '/") ? 1 : 0;
}
|
public boolean rename(File f1,
File f2) {
// Keep canonicalization caches in sync after file deletion
// and renaming operations. Could be more clever than this
// (i.e., only remove/update affected entries) but probably
// not worth it since these entries expire after 30 seconds
// anyway.
cache.clear();
javaHomePrefixCache.clear();
return rename0(f1, f2);
}
|
public String resolve(File f) {
if (isAbsolute(f)) return f.getPath();
return resolve(System.getProperty("user.dir"), f.getPath());
}
|
public String resolve(String parent,
String child) {
if (child.equals("")) return parent;
if (child.charAt(0) == '/") {
if (parent.equals("/")) return child;
return parent + child;
}
if (parent.equals("/")) return parent + child;
return parent + '/" + child;
}
|
public native boolean setLastModifiedTime(File f,
long time)
|
public native boolean setPermission(File f,
int access,
boolean enable,
boolean owneronly)
|
public native boolean setReadOnly(File f)
|