129
* Unquote "%" + hex quotes characters
131
* @param str The string to unquote or null.
133
* @return The unquoted string or null if str was null.
135
* @exception MalformedURLException If the given string contains invalid
139
public static String unquote(String str) throws MalformedURLException
144
final int MAX_BYTES_PER_UTF_8_CHAR = 3;
145
byte[] buf = new byte[str.length()*MAX_BYTES_PER_UTF_8_CHAR];
147
for (int i = 0; i < str.length(); i++)
149
char c = str.charAt(i);
152
if (i + 2 >= str.length())
153
throw new MalformedURLException(str + " : Invalid quoted character");
154
int hi = Character.digit(str.charAt(++i), 16);
155
int lo = Character.digit(str.charAt(++i), 16);
156
if (lo < 0 || hi < 0)
157
throw new MalformedURLException(str + " : Invalid quoted character");
158
buf[pos++] = (byte) (hi * 16 + lo);
162
byte [] c_as_bytes = Character.toString(c).getBytes("utf-8");
163
final int c_length = c_as_bytes.length;
164
System.arraycopy(c_as_bytes, 0, buf, pos, c_length);
167
catch (java.io.UnsupportedEncodingException x2) {
168
throw (Error) new InternalError().initCause(x2);
172
buf[pos++] = (byte) c;
176
return new String(buf, 0, pos, "utf-8");
178
catch (java.io.UnsupportedEncodingException x2)
180
throw (Error) new InternalError().initCause(x2);
128
185
* "Connects" to the file by opening it.
130
187
public void connect() throws IOException
136
193
// If not connected, then file needs to be openned.
137
file = new File (getURL().getFile());
194
file = new File (unquote(getURL().getFile()));
139
196
if (! file.isDirectory())