diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-18 00:59:33 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-18 00:59:33 +0000 |
commit | 15d27402f51cf831d82aa31271f5c01855b4f2cf (patch) | |
tree | 4c44aaa3ed1ee1b4f15732664c05cfc9214e1fa9 /libjava/classpath/gnu/java/net/protocol/file/Connection.java | |
parent | 820206ad46c6fc0131d5771ec1051267022e875d (diff) | |
download | ppe42-gcc-15d27402f51cf831d82aa31271f5c01855b4f2cf.tar.gz ppe42-gcc-15d27402f51cf831d82aa31271f5c01855b4f2cf.zip |
Imported GNU Classpath gcj-import-20051117.
* gnu/java/net/protocol/file/Connection.java: Removed, fully merged.
* sources.am: Regenerated.
* Makefile.in: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107153 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/gnu/java/net/protocol/file/Connection.java')
-rw-r--r-- | libjava/classpath/gnu/java/net/protocol/file/Connection.java | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/libjava/classpath/gnu/java/net/protocol/file/Connection.java b/libjava/classpath/gnu/java/net/protocol/file/Connection.java index 52bd0484510..8e4a413667d 100644 --- a/libjava/classpath/gnu/java/net/protocol/file/Connection.java +++ b/libjava/classpath/gnu/java/net/protocol/file/Connection.java @@ -59,6 +59,7 @@ import java.security.Permission; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.net.MalformedURLException; /** * This subclass of java.net.URLConnection models a URLConnection via @@ -125,6 +126,54 @@ public class Connection extends URLConnection } /** + * Unquote "%" + hex quotes characters + * + * @param str The string to unquote or null. + * + * @return The unquoted string or null if str was null. + * + * @exception MalformedURLException If the given string contains invalid + * escape sequences. + * + * Sadly the same as URI.unquote, but there's nothing we can do to + * make it accessible. + * + */ + public static String unquote(String str) throws MalformedURLException + { + if (str == null) + return null; + byte[] buf = new byte[str.length()]; + int pos = 0; + for (int i = 0; i < str.length(); i++) + { + char c = str.charAt(i); + if (c > 127) + throw new MalformedURLException(str + " : Invalid character"); + if (c == '%') + { + if (i + 2 >= str.length()) + throw new MalformedURLException(str + " : Invalid quoted character"); + int hi = Character.digit(str.charAt(++i), 16); + int lo = Character.digit(str.charAt(++i), 16); + if (lo < 0 || hi < 0) + throw new MalformedURLException(str + " : Invalid quoted character"); + buf[pos++] = (byte) (hi * 16 + lo); + } + else + buf[pos++] = (byte) c; + } + try + { + return new String(buf, 0, pos, "utf-8"); + } + catch (java.io.UnsupportedEncodingException x2) + { + throw (Error) new InternalError().initCause(x2); + } + } + + /** * "Connects" to the file by opening it. */ public void connect() throws IOException @@ -134,7 +183,7 @@ public class Connection extends URLConnection return; // If not connected, then file needs to be openned. - file = new File (getURL().getFile()); + file = new File (unquote(getURL().getFile())); if (! file.isDirectory()) { |