1 |
/* Connection - jar url connection for java.net |
/* Connection - jar url connection for java.net |
2 |
Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. |
Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
68 |
{ |
{ |
69 |
private static Hashtable cache = new Hashtable(); |
private static Hashtable cache = new Hashtable(); |
70 |
private static final int READBUFSIZE = 4*1024; |
private static final int READBUFSIZE = 4*1024; |
|
private static boolean is_trying = false; |
|
71 |
|
|
72 |
public static synchronized JarFile get (URL url) throws IOException |
public static synchronized JarFile get (URL url) throws IOException |
73 |
{ |
{ |
76 |
if (jf != null) |
if (jf != null) |
77 |
return jf; |
return jf; |
78 |
|
|
79 |
if (is_trying) |
if ("file".equals (url.getProtocol())) |
80 |
return null; |
{ |
81 |
|
File f = new File (url.getFile()); |
82 |
try |
jf = new JarFile (f, true, ZipFile.OPEN_READ); |
83 |
{ |
} |
84 |
is_trying = true; |
else |
85 |
|
{ |
86 |
if ("file".equals (url.getProtocol())) |
URLConnection urlconn = url.openConnection(); |
87 |
{ |
InputStream is = urlconn.getInputStream(); |
88 |
File f = new File (url.getFile()); |
byte[] buf = new byte [READBUFSIZE]; |
89 |
jf = new JarFile (f, true, ZipFile.OPEN_READ); |
File f = File.createTempFile ("cache", "jar"); |
90 |
} |
FileOutputStream fos = new FileOutputStream (f); |
91 |
else |
int len = 0; |
92 |
{ |
|
93 |
URLConnection urlconn = url.openConnection(); |
while ((len = is.read (buf)) != -1) |
94 |
InputStream is = urlconn.getInputStream(); |
{ |
95 |
byte[] buf = new byte [READBUFSIZE]; |
fos.write (buf, 0, len); |
96 |
File f = File.createTempFile ("cache", "jar"); |
} |
97 |
FileOutputStream fos = new FileOutputStream (f); |
|
98 |
int len = 0; |
fos.close(); |
99 |
|
// Always verify the Manifest, open read only and delete when done. |
100 |
while ((len = is.read (buf)) != -1) |
// XXX ZipFile.OPEN_DELETE not yet implemented. |
101 |
{ |
// jf = new JarFile (f, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); |
102 |
fos.write (buf, 0, len); |
jf = new JarFile (f, true, ZipFile.OPEN_READ); |
103 |
} |
} |
|
|
|
|
fos.close(); |
|
|
// Always verify the Manifest, open read only and delete when done. |
|
|
// XXX ZipFile.OPEN_DELETE not yet implemented. |
|
|
// jf = new JarFile (f, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); |
|
|
jf = new JarFile (f, true, ZipFile.OPEN_READ); |
|
|
} |
|
104 |
|
|
105 |
cache.put (url, jf); |
cache.put (url, jf); |
|
} |
|
|
finally |
|
|
{ |
|
|
is_trying = false; |
|
|
} |
|
106 |
|
|
107 |
return jf; |
return jf; |
108 |
} |
} |