Connection.java (unquote): New method.
2005-07-13 Andrew Haley <aph@redhat.com> * gnu/java/net/protocol/file/Connection.java (unquote): New method. (connect): Unquote filename. gnu/java/net/protocol/jar/Connection.java (getInputStream): Likewise. (getJarFile): Likewise. * java/net/URLConnection.java (getContentHandler): Guard cast with instaceof. * java/net/URL.java (URL): If the file part of a spec is absolute, ignore the file part of its context. From-SVN: r102029
This commit is contained in:
committed by
Andrew Haley
parent
b11e14262e
commit
3fefd0193c
@@ -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
|
||||
@@ -124,6 +125,54 @@ public class Connection extends URLConnection
|
||||
permission = new FilePermission(getURL().getFile(), DEFAULT_PERMISSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user