| Method from java.io.Win32FileSystem Detail: |
public String canonicalize(String path) throws IOException {
// If path is a drive letter only then skip canonicalization
int len = path.length();
if ((len == 2) &&
(isLetter(path.charAt(0))) &&
(path.charAt(1) == ':")) {
char c = path.charAt(0);
if ((c >= 'A") && (c < = 'Z"))
return path;
return "" + ((char) (c-32)) + ':";
} else if ((len == 3) &&
(isLetter(path.charAt(0))) &&
(path.charAt(1) == ':") &&
(path.charAt(2) == '\\")) {
char c = path.charAt(0);
if ((c >= 'A") && (c < = 'Z"))
return path;
return "" + ((char) (c-32)) + ':" + '\\";
}
if (!useCanonCaches) {
return canonicalize0(path);
} else {
String res = cache.get(path);
if (res == null) {
String dir = null;
String resDir = null;
if (useCanonPrefixCache) {
dir = parentOrNull(path);
if (dir != null) {
resDir = prefixCache.get(dir);
if (resDir != null) {
// Hit only in prefix cache; full path is canonical,
// but we need to get the canonical name of the file
// in this directory to get the appropriate capitalization
String filename = path.substring(1 + dir.length());
res = canonicalizeWithPrefix(resDir, filename);
cache.put(dir + File.separatorChar + filename, res);
}
}
}
if (res == null) {
res = canonicalize0(path);
cache.put(path, res);
if (useCanonPrefixCache && dir != null) {
resDir = parentOrNull(res);
if (resDir != null) {
File f = new File(res);
if (f.exists() && !f.isDirectory()) {
prefixCache.put(dir, resDir);
}
}
}
}
}
assert canonicalize0(path).equalsIgnoreCase(res);
return res;
}
}
|
protected native String canonicalize0(String path) throws IOException
|
protected String canonicalizeWithPrefix(String canonicalPrefix,
String filename) throws IOException {
return canonicalizeWithPrefix0(canonicalPrefix,
canonicalPrefix + File.separatorChar + filename);
}
|
protected native String canonicalizeWithPrefix0(String canonicalPrefix,
String pathWithCanonicalPrefix) throws IOException
|
public native boolean checkAccess(File f,
int access)
|
public int compare(File f1,
File f2) {
return f1.getPath().compareToIgnoreCase(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();
prefixCache.clear();
return delete0(f);
}
|
protected native boolean delete0(File f)
|
public String fromURIPath(String path) {
String p = path;
if ((p.length() > 2) && (p.charAt(2) == ':")) {
// "/c:/foo" -- > "c:/foo"
p = p.substring(1);
// "c:/foo/" -- > "c:/foo", but "c:/" -- > "c:/"
if ((p.length() > 3) && p.endsWith("/"))
p = p.substring(0, p.length() - 1);
} else if ((p.length() > 1) && p.endsWith("/")) {
// "/foo/" -- > "/foo"
p = p.substring(0, p.length() - 1);
}
return p;
}
|
public native int getBooleanAttributes(File f)
|
public String getDefaultParent() {
return ("" + slash);
}
|
protected native String getDriveDirectory(int drive)
|
public native long getLastModifiedTime(File f)
|
public native long getLength(File f)
|
public char getPathSeparator() {
return semicolon;
}
|
public char getSeparator() {
return slash;
}
|
public long getSpace(File f,
int t) {
if (f.exists()) {
File file = (f.isDirectory() ? f : f.getParentFile());
return getSpace0(file, t);
}
return 0;
}
|
public int hashCode(File f) {
/* Could make this more efficient: String.hashCodeIgnoreCase */
return f.getPath().toLowerCase(Locale.ENGLISH).hashCode() ^ 1234321;
}
|
public boolean isAbsolute(File f) {
int pl = f.getPrefixLength();
return (((pl == 2) && (f.getPath().charAt(0) == slash))
|| (pl == 3));
}
|
public native String[] list(File f)
|
public File[] listRoots() {
int ds = listRoots0();
int n = 0;
for (int i = 0; i < 26; i++) {
if (((ds > > i) & 1) != 0) {
if (!access((char)('A" + i) + ":" + slash))
ds &= ~(1 < < i);
else
n++;
}
}
File[] fs = new File[n];
int j = 0;
char slash = this.slash;
for (int i = 0; i < 26; i++) {
if (((ds > > i) & 1) != 0)
fs[j++] = new File((char)('A" + i) + ":" + slash);
}
return fs;
}
|
public String normalize(String path) {
int n = path.length();
char slash = this.slash;
char altSlash = this.altSlash;
char prev = 0;
for (int i = 0; i < n; i++) {
char c = path.charAt(i);
if (c == altSlash)
return normalize(path, n, (prev == slash) ? i - 1 : i);
if ((c == slash) && (prev == slash) && (i > 1))
return normalize(path, n, i - 1);
if ((c == ':") && (i > 1))
return normalize(path, n, 0);
prev = c;
}
if (prev == slash) return normalize(path, n, n - 1);
return path;
}
|
static String parentOrNull(String path) {
if (path == null) return null;
char sep = File.separatorChar;
char altSep = '/";
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;
}
if (nonDotCount == 0) {
// Punt on pathnames ending in a .
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 ||
path.charAt(idx - 1) == altSep) {
// Punt on pathnames containing adjacent slashes
// toward the end
return null;
}
return path.substring(0, idx);
} else if (c == altSep) {
// Punt on pathnames containing both backward and
// forward slashes
return null;
} else if (c == '*" || c == '?") {
// Punt on pathnames containing wildcards
return null;
} else {
++nonDotCount;
adjacentDots = 0;
}
--idx;
}
return null;
}
|
public int prefixLength(String path) {
char slash = this.slash;
int n = path.length();
if (n == 0) return 0;
char c0 = path.charAt(0);
char c1 = (n > 1) ? path.charAt(1) : 0;
if (c0 == slash) {
if (c1 == slash) return 2; /* Absolute UNC pathname "\\\\foo" */
return 1; /* Drive-relative "\\foo" */
}
if (isLetter(c0) && (c1 == ':")) {
if ((n > 2) && (path.charAt(2) == slash))
return 3; /* Absolute local pathname "z:\\foo" */
return 2; /* Directory-relative "z:foo" */
}
return 0; /* Completely relative */
}
|
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();
prefixCache.clear();
return rename0(f1, f2);
}
|
protected native boolean rename0(File f1,
File f2)
|
public String resolve(File f) {
String path = f.getPath();
int pl = f.getPrefixLength();
if ((pl == 2) && (path.charAt(0) == slash))
return path; /* UNC */
if (pl == 3)
return path; /* Absolute local */
if (pl == 0)
return getUserPath() + slashify(path); /* Completely relative */
if (pl == 1) { /* Drive-relative */
String up = getUserPath();
String ud = getDrive(up);
if (ud != null) return ud + path;
return up + path; /* User dir is a UNC path */
}
if (pl == 2) { /* Directory-relative */
String up = getUserPath();
String ud = getDrive(up);
if ((ud != null) && path.startsWith(ud))
return up + slashify(path.substring(2));
char drive = path.charAt(0);
String dir = getDriveDirectory(drive);
String np;
if (dir != null) {
/* When resolving a directory-relative path that refers to a
drive other than the current drive, insist that the caller
have read permission on the result */
String p = drive + (':" + dir + slashify(path.substring(2)));
SecurityManager security = System.getSecurityManager();
try {
if (security != null) security.checkRead(p);
} catch (SecurityException x) {
/* Don't disclose the drive's directory in the exception */
throw new SecurityException("Cannot resolve path " + path);
}
return p;
}
return drive + ":" + slashify(path.substring(2)); /* fake it */
}
throw new InternalError("Unresolvable path: " + path);
}
|
public String resolve(String parent,
String child) {
int pn = parent.length();
if (pn == 0) return child;
int cn = child.length();
if (cn == 0) return parent;
String c = child;
int childStart = 0;
int parentEnd = pn;
if ((cn > 1) && (c.charAt(0) == slash)) {
if (c.charAt(1) == slash) {
/* Drop prefix when child is a UNC pathname */
childStart = 2;
} else {
/* Drop prefix when child is drive-relative */
childStart = 1;
}
if (cn == childStart) { // Child is double slash
if (parent.charAt(pn - 1) == slash)
return parent.substring(0, pn - 1);
return parent;
}
}
if (parent.charAt(pn - 1) == slash)
parentEnd--;
int strlen = parentEnd + cn - childStart;
char[] theChars = null;
if (child.charAt(childStart) == slash) {
theChars = new char[strlen];
parent.getChars(0, parentEnd, theChars, 0);
child.getChars(childStart, cn, theChars, parentEnd);
} else {
theChars = new char[strlen + 1];
parent.getChars(0, parentEnd, theChars, 0);
theChars[parentEnd] = slash;
child.getChars(childStart, cn, theChars, parentEnd + 1);
}
return new String(theChars);
}
|
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)
|