Lines 14-23
Link Here
|
14 |
package org.netbeans.core.projects.cache; |
14 |
package org.netbeans.core.projects.cache; |
15 |
|
15 |
|
16 |
import java.io.*; |
16 |
import java.io.*; |
|
|
17 |
import java.lang.reflect.InvocationTargetException; |
18 |
import java.lang.reflect.Method; |
19 |
import java.net.MalformedURLException; |
17 |
import java.net.URL; |
20 |
import java.net.URL; |
18 |
import java.util.Iterator; |
21 |
import java.util.Iterator; |
19 |
import java.util.List; |
22 |
import java.util.List; |
20 |
import java.util.zip.CRC32; |
23 |
import java.util.zip.CRC32; |
|
|
24 |
import org.openide.ErrorManager; |
21 |
|
25 |
|
22 |
import org.xml.sax.SAXException; |
26 |
import org.xml.sax.SAXException; |
23 |
|
27 |
|
Lines 58-64
Link Here
|
58 |
public FileSystem createLoadedFileSystem() throws IOException { |
62 |
public FileSystem createLoadedFileSystem() throws IOException { |
59 |
if (cacheFile.exists()) { |
63 |
if (cacheFile.exists()) { |
60 |
try { |
64 |
try { |
61 |
return new XMLFileSystem(cacheFile.toURL()); |
65 |
return new XMLFileSystem(fileToURL(cacheFile)); |
62 |
} catch (SAXException saxe) { |
66 |
} catch (SAXException saxe) { |
63 |
IOException ioe = new IOException(saxe.toString()); |
67 |
IOException ioe = new IOException(saxe.toString()); |
64 |
LayerCacheManager.err.annotate(ioe, saxe); |
68 |
LayerCacheManager.err.annotate(ioe, saxe); |
Lines 71-77
Link Here
|
71 |
|
75 |
|
72 |
public void load(FileSystem fs) throws IOException { |
76 |
public void load(FileSystem fs) throws IOException { |
73 |
try { |
77 |
try { |
74 |
((XMLFileSystem)fs).setXmlUrl(cacheFile.toURL()); |
78 |
((XMLFileSystem)fs).setXmlUrl(fileToURL(cacheFile)); |
75 |
} catch (Exception e) { |
79 |
} catch (Exception e) { |
76 |
IOException ioe = new IOException(e.toString()); |
80 |
IOException ioe = new IOException(e.toString()); |
77 |
LayerCacheManager.err.annotate(ioe, e); |
81 |
LayerCacheManager.err.annotate(ioe, e); |
Lines 165-171
Link Here
|
165 |
hex = "0" + hex; // NOI18N |
169 |
hex = "0" + hex; // NOI18N |
166 |
} |
170 |
} |
167 |
File data = new File(datadir, "data_" + hex); // NOI18N |
171 |
File data = new File(datadir, "data_" + hex); // NOI18N |
168 |
url = data.toURL().toString(); |
172 |
url = fileToURL(data).toExternalForm(); |
169 |
if (!data.isFile()) { |
173 |
if (!data.isFile()) { |
170 |
OutputStream os = new FileOutputStream(data); |
174 |
OutputStream os = new FileOutputStream(data); |
171 |
try { |
175 |
try { |
Lines 220-225
Link Here
|
220 |
} |
224 |
} |
221 |
|
225 |
|
222 |
return false; |
226 |
return false; |
|
|
227 |
} |
228 |
|
229 |
/** Convert a file to a URL as safely as possible. |
230 |
* Under JDK 1.4, handle hash marks etc. |
231 |
* Unfortunately it was decided not to fix the major bugs |
232 |
* in the JDK 1.3 implementation, so a separate API is needed. |
233 |
* @see #27330 |
234 |
*/ |
235 |
private static URL fileToURL(File f) throws MalformedURLException { |
236 |
if (!System.getProperty("java.specification.version").startsWith("1.3")) { // NOI18N |
237 |
try { |
238 |
Method m = File.class.getMethod("toURI", null); // NOI18N |
239 |
Object o = m.invoke(f, null); |
240 |
m = o.getClass().getMethod("toURL", null); // NOI18N |
241 |
return (URL)m.invoke(o, null); |
242 |
} catch (InvocationTargetException e) { |
243 |
throw (MalformedURLException)e.getTargetException(); |
244 |
} catch (Exception e) { |
245 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); |
246 |
} |
247 |
} |
248 |
return f.toURL(); |
223 |
} |
249 |
} |
224 |
|
250 |
|
225 |
} |
251 |
} |