diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/vm/reference/java/io | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/classpath/vm/reference/java/io')
-rw-r--r-- | libjava/classpath/vm/reference/java/io/VMFile.java | 105 | ||||
-rw-r--r-- | libjava/classpath/vm/reference/java/io/VMObjectInputStream.java | 39 |
2 files changed, 105 insertions, 39 deletions
diff --git a/libjava/classpath/vm/reference/java/io/VMFile.java b/libjava/classpath/vm/reference/java/io/VMFile.java index 2f48aad..13d256d 100644 --- a/libjava/classpath/vm/reference/java/io/VMFile.java +++ b/libjava/classpath/vm/reference/java/io/VMFile.java @@ -38,6 +38,9 @@ exception statement from your version. */ package java.io; +import java.net.MalformedURLException; +import java.net.URL; + import gnu.classpath.Configuration; import gnu.java.io.PlatformHelper; @@ -209,6 +212,108 @@ final class VMFile } /** + * Returns the path as an absolute path name. The value returned is the + * current directory plus the separatory string plus the path of the file. + * The current directory is determined from the <code>user.dir</code> system + * property. + * + * @param path the path to convert to absolute path + * + * @return the absolute path that corresponds to <code>path</code> + */ + static String getAbsolutePath(String path) + { + if (File.separatorChar == '\\' + && path.length() > 0 && path.charAt (0) == '\\') + { + // On Windows, even if the path starts with a '\\' it is not + // really absolute until we prefix the drive specifier from + // the current working directory to it. + return System.getProperty ("user.dir").substring (0, 2) + path; + } + else if (File.separatorChar == '\\' + && path.length() > 1 && path.charAt (1) == ':' + && ((path.charAt (0) >= 'a' && path.charAt (0) <= 'z') + || (path.charAt (0) >= 'A' && path.charAt (0) <= 'Z'))) + { + // On Windows, a process has a current working directory for + // each drive and a path like "G:foo\bar" would mean the + // absolute path "G:\wombat\foo\bar" if "\wombat" is the + // working directory on the G drive. + String drvDir = null; + try + { + drvDir = new File (path.substring (0, 2)).getCanonicalPath(); + } + catch (IOException e) + { + drvDir = path.substring (0, 2) + "\\"; + } + + // Note: this would return "C:\\." for the path "C:.", if "\" + // is the working folder on the C drive, but this is + // consistent with what Sun's JRE 1.4.1.01 actually returns! + if (path.length() > 2) + return drvDir + '\\' + path.substring (2, path.length()); + else + return drvDir; + } + else if (path.equals("")) + return System.getProperty ("user.dir"); + else + return System.getProperty ("user.dir") + File.separatorChar + path; + } + + /** + * This method returns true if the path represents an absolute file + * path and false if it does not. The definition of an absolute path varies + * by system. As an example, on GNU systems, a path is absolute if it starts + * with a "/". + * + * @param path the path to check + * + * @return <code>true</code> if path represents an absolute file name, + * <code>false</code> otherwise. + */ + static boolean isAbsolute(String path) + { + if (File.separatorChar == '\\') + return path.startsWith(File.separator + File.separator) + || (path.length() > 2 + && ((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') + || (path.charAt(0) >= 'A' && path.charAt(0) <= 'Z')) + && path.charAt(1) == ':' + && path.charAt(2) == '\\'); + else + return path.startsWith(File.separator); + } + + /** + * Returns a <code>URL</code> with the <code>file:</code> + * protocol that represents this file. The exact form of this URL is + * system dependent. + * + * @param file the file to convert to URL + * + * @return a <code>URL</code> for this object. + * + * @throws MalformedURLException if the URL cannot be created + * successfully. + */ + static URL toURL(File file) + throws MalformedURLException + { + // On Win32, Sun's JDK returns URLs of the form "file:/c:/foo/bar.txt", + // while on UNIX, it returns URLs of the form "file:/foo/bar.txt". + if (File.separatorChar == '\\') + return new URL ("file:/" + file.getAbsolutePath().replace ('\\', '/') + + (file.isDirectory() ? "/" : "")); + else + return new URL ("file:" + file.getAbsolutePath() + + (file.isDirectory() ? "/" : "")); + } + + /** * This method returns a canonical representation of the pathname of * this file. The actual form of the canonical representation is * system-dependent. On the GNU system, conversion to canonical diff --git a/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java b/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java index 5fb56fc..be0f8eb 100644 --- a/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java +++ b/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java @@ -40,10 +40,7 @@ exception statement from your version. */ package java.io; import gnu.classpath.Configuration; -import gnu.classpath.VMStackWalker; import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedAction; final class VMObjectInputStream { @@ -56,42 +53,6 @@ final class VMObjectInputStream } /** - * PrivilegedAction needed for Class.getClassLoader() - */ - private static PrivilegedAction loaderAction = new PrivilegedAction() - { - /** - * Returns the first user defined class loader on the call stack, or the - * context class loader of the current thread, when no non-null class loader - * was found. - */ - public Object run() - { - Class[] ctx = VMStackWalker.getClassContext(); - - for (int i = 0; i < ctx.length; i++) - { - ClassLoader cl = ctx[i].getClassLoader(); - if (cl != null) - return cl; - } - return Thread.currentThread().getContextClassLoader(); - } - }; - - /** - * Returns the first user defined class loader on the call stack, or the - * context class loader of the current thread, when no non-null class loader - * was found. - * - * @return the class loader - */ - static ClassLoader currentClassLoader() - { - return (ClassLoader) AccessController.doPrivileged(loaderAction); - } - - /** * Allocates a new Object of type clazz but without running the * default constructor on it. It then calls the given constructor on * it. The given constructor method comes from the constr_clazz |