47 |
import java.net.ProtocolException; |
import java.net.ProtocolException; |
48 |
import java.net.URL; |
import java.net.URL; |
49 |
import java.net.URLConnection; |
import java.net.URLConnection; |
50 |
|
import java.text.SimpleDateFormat; |
51 |
|
import java.util.Date; |
52 |
import java.util.Hashtable; |
import java.util.Hashtable; |
53 |
|
import java.util.Locale; |
54 |
import java.util.jar.JarEntry; |
import java.util.jar.JarEntry; |
55 |
import java.util.jar.JarFile; |
import java.util.jar.JarFile; |
56 |
import java.util.zip.ZipFile; |
import java.util.zip.ZipFile; |
63 |
*/ |
*/ |
64 |
public final class Connection extends JarURLConnection |
public final class Connection extends JarURLConnection |
65 |
{ |
{ |
66 |
|
/** |
67 |
|
* HTTP-style DateFormat, used to format the last-modified header. |
68 |
|
* Lazy initialized since jar files are used during bootstrapping. |
69 |
|
*/ |
70 |
|
private static SimpleDateFormat dateFormat; |
71 |
|
|
72 |
private JarFile jar_file; |
private JarFile jar_file; |
73 |
private JarEntry jar_entry; |
private JarEntry jar_entry; |
74 |
private URL jar_url; |
private URL jar_url; |
91 |
|
|
92 |
if ("file".equals (url.getProtocol())) |
if ("file".equals (url.getProtocol())) |
93 |
{ |
{ |
94 |
File f = new File (url.getFile()); |
String fn = url.getFile(); |
95 |
|
fn = gnu.java.net.protocol.file.Connection.unquote(fn); |
96 |
|
File f = new File (fn); |
97 |
jf = new JarFile (f, true, ZipFile.OPEN_READ); |
jf = new JarFile (f, true, ZipFile.OPEN_READ); |
98 |
} |
} |
99 |
else |
else |
176 |
return jar_file; |
return jar_file; |
177 |
} |
} |
178 |
|
|
179 |
|
public String getHeaderField(String field) |
180 |
|
{ |
181 |
|
try |
182 |
|
{ |
183 |
|
if (!connected) |
184 |
|
connect(); |
185 |
|
|
186 |
|
if (field.equals("content-type")) |
187 |
|
return guessContentTypeFromName(getJarEntry().getName()); |
188 |
|
else if (field.equals("content-length")) |
189 |
|
return Long.toString(getJarEntry().getSize()); |
190 |
|
else if (field.equals("last-modified")) |
191 |
|
{ |
192 |
|
// Both creating and manipulating dateFormat need synchronization. |
193 |
|
synchronized (this.getClass()) |
194 |
|
{ |
195 |
|
if (dateFormat == null) |
196 |
|
dateFormat = new SimpleDateFormat |
197 |
|
("EEE, dd MMM yyyy hh:mm:ss 'GMT'", |
198 |
|
new Locale ("En", "Us", "Unix")); |
199 |
|
|
200 |
|
return dateFormat.format(new Date(getJarEntry().getTime())); |
201 |
|
} |
202 |
|
} |
203 |
|
} |
204 |
|
catch (IOException e) |
205 |
|
{ |
206 |
|
// Fall through. |
207 |
|
} |
208 |
|
return null; |
209 |
|
} |
210 |
|
|
211 |
public int getContentLength() |
public int getContentLength() |
212 |
{ |
{ |
213 |
if (!connected) |
if (!connected) |
215 |
|
|
216 |
return (int) jar_entry.getSize(); |
return (int) jar_entry.getSize(); |
217 |
} |
} |
218 |
|
|
219 |
|
public long getLastModified() |
220 |
|
{ |
221 |
|
if (!connected) |
222 |
|
return -1; |
223 |
|
|
224 |
|
try |
225 |
|
{ |
226 |
|
return getJarEntry().getTime(); |
227 |
|
} |
228 |
|
catch (IOException e) |
229 |
|
{ |
230 |
|
return -1; |
231 |
|
} |
232 |
|
} |
233 |
} |
} |