diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-01 23:38:13 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-01 23:38:13 +0000 |
commit | d03da085bc50e83dbbf4ec4e29fdf17fa9973e6e (patch) | |
tree | 4cd6d3bffb8812360e139400a1ec89459ba0a0d9 /libjava/java/net/URLStreamHandler.java | |
parent | b25365b4d3ea834d6c65c5893a85a7df172f56e9 (diff) | |
download | ppe42-gcc-d03da085bc50e83dbbf4ec4e29fdf17fa9973e6e.tar.gz ppe42-gcc-d03da085bc50e83dbbf4ec4e29fdf17fa9973e6e.zip |
2003-03-01 Ranjit Mathew <rmathew@hotmail.com>
* java/io/File (getAbsolutePath): Prefix drive specifier on
Windows for paths starting with a '\'.
(toURL): Make URL more consistent with what Sun's JDK returns.
* java/io/natFileWin32.cc (java::io::File::isAbsolute): Return
true only if the path is a UNC network path or it starts with a
drive specifier.
* java/net/URLStreamHandler.java (parseURL): Correct minor typo.
Be prepared to handle either '/' or '\\' in the file path for
Windows if using the "file" protocol.
Canonicalise the file path if using a relative path in the given
context and the "file" protocol.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63635 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/net/URLStreamHandler.java')
-rw-r--r-- | libjava/java/net/URLStreamHandler.java | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/libjava/java/net/URLStreamHandler.java b/libjava/java/net/URLStreamHandler.java index 7f866440f2f..d3dd3ccf0f7 100644 --- a/libjava/java/net/URLStreamHandler.java +++ b/libjava/java/net/URLStreamHandler.java @@ -1,5 +1,5 @@ /* URLStreamHandler.java -- Abstract superclass for all protocol handlers - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,6 +39,7 @@ exception statement from your version. */ package java.net; import java.io.IOException; +import java.io.File; /* * Written using on-line Java Platform 1.2 API Specification, as well @@ -112,7 +113,7 @@ public abstract class URLStreamHandler * subclasses that implement protocols with URL's the follow a different * syntax should override this method. The lone exception is that if * the protocol name set in the URL is "file", this method will accept - * a an empty hostname (i.e., "file:///"), which is legal for that protocol + * an empty hostname (i.e., "file:///"), which is legal for that protocol * * @param url The URL object in which to store the results * @param spec The String-ized URL to parse @@ -176,8 +177,32 @@ public abstract class URLStreamHandler else if (start < end) { // Context is available, but only override it if there is a new file. - file = file.substring(0, file.lastIndexOf('/')) - + '/' + spec.substring(start, end); + char sepChar = '/'; + int lastSlash = file.lastIndexOf (sepChar); + if (lastSlash < 0 && File.separatorChar != sepChar + && url.getProtocol ().equals ("file")) + { + // On Windows, even '\' is allowed in a "file" URL. + sepChar = File.separatorChar; + lastSlash = file.lastIndexOf (sepChar); + } + + file = file.substring(0, lastSlash) + + sepChar + spec.substring (start, end); + + if (url.getProtocol ().equals ("file")) + { + // For "file" URLs constructed relative to a context, we + // need to canonicalise the file path. + try + { + file = new File (file).getCanonicalPath (); + } + catch (IOException e) + { + } + } + ref = null; } |