59 |
import java.text.SimpleDateFormat; |
import java.text.SimpleDateFormat; |
60 |
import java.util.Date; |
import java.util.Date; |
61 |
import java.util.Locale; |
import java.util.Locale; |
62 |
|
import java.net.MalformedURLException; |
63 |
|
|
64 |
/** |
/** |
65 |
* This subclass of java.net.URLConnection models a URLConnection via |
* This subclass of java.net.URLConnection models a URLConnection via |
126 |
} |
} |
127 |
|
|
128 |
/** |
/** |
129 |
|
* Unquote "%" + hex quotes characters |
130 |
|
* |
131 |
|
* @param str The string to unquote or null. |
132 |
|
* |
133 |
|
* @return The unquoted string or null if str was null. |
134 |
|
* |
135 |
|
* @exception MalformedURLException If the given string contains invalid |
136 |
|
* escape sequences. |
137 |
|
* |
138 |
|
* Sadly the same as URI.unquote, but there's nothing we can do to |
139 |
|
* make it accessible. |
140 |
|
* |
141 |
|
*/ |
142 |
|
public static String unquote(String str) throws MalformedURLException |
143 |
|
{ |
144 |
|
if (str == null) |
145 |
|
return null; |
146 |
|
byte[] buf = new byte[str.length()]; |
147 |
|
int pos = 0; |
148 |
|
for (int i = 0; i < str.length(); i++) |
149 |
|
{ |
150 |
|
char c = str.charAt(i); |
151 |
|
if (c > 127) |
152 |
|
throw new MalformedURLException(str + " : Invalid character"); |
153 |
|
if (c == '%') |
154 |
|
{ |
155 |
|
if (i + 2 >= str.length()) |
156 |
|
throw new MalformedURLException(str + " : Invalid quoted character"); |
157 |
|
int hi = Character.digit(str.charAt(++i), 16); |
158 |
|
int lo = Character.digit(str.charAt(++i), 16); |
159 |
|
if (lo < 0 || hi < 0) |
160 |
|
throw new MalformedURLException(str + " : Invalid quoted character"); |
161 |
|
buf[pos++] = (byte) (hi * 16 + lo); |
162 |
|
} |
163 |
|
else |
164 |
|
buf[pos++] = (byte) c; |
165 |
|
} |
166 |
|
try |
167 |
|
{ |
168 |
|
return new String(buf, 0, pos, "utf-8"); |
169 |
|
} |
170 |
|
catch (java.io.UnsupportedEncodingException x2) |
171 |
|
{ |
172 |
|
throw (Error) new InternalError().initCause(x2); |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
|
/** |
177 |
* "Connects" to the file by opening it. |
* "Connects" to the file by opening it. |
178 |
*/ |
*/ |
179 |
public void connect() throws IOException |
public void connect() throws IOException |
183 |
return; |
return; |
184 |
|
|
185 |
// If not connected, then file needs to be openned. |
// If not connected, then file needs to be openned. |
186 |
file = new File (getURL().getFile()); |
file = new File (unquote(getURL().getFile())); |
187 |
|
|
188 |
if (! file.isDirectory()) |
if (! file.isDirectory()) |
189 |
{ |
{ |