MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / fileExists

Method fileExists

src/org/opensourcephysics/ejs/control/Utils.java:22–57  ·  view source on GitHub ↗
(String _codebase, String _filename)

Source from the content-addressed store, hash-verified

20 static private java.util.Hashtable<String, ImageIcon> cacheImages = new java.util.Hashtable<String, ImageIcon>();
21
22 static public boolean fileExists(String _codebase, String _filename) {
23 if(_filename==null) {
24 return false;
25 }
26 if(cacheImages.get(_filename)!=null) {
27 return true;
28 }
29 if (OSPRuntime.isJS && _codebase == null) {
30 URL u = Utils.class.getClassLoader().getResource(_filename);
31 return (u != null);
32 }
33 if(_codebase!=null) {
34 if(_codebase.startsWith("file:")) { //$NON-NLS-1$
35 _codebase = "file:///"+_codebase.substring(6); //$NON-NLS-1$
36 }
37 if(!_filename.startsWith("/") && !_codebase.endsWith("/")) { //$NON-NLS-1$
38 _codebase += "/"; //$NON-NLS-1$
39 }
40 }
41 int index = _filename.indexOf('+');
42 if(index>=0) {
43 return fileExistsInJar(_codebase, _filename.substring(0, index), _filename.substring(index+1));
44 } else if(_codebase==null) {
45 java.io.File file = new java.io.File(_filename);
46 return file.exists();
47 } else {
48 try {
49 java.net.URL url = new java.net.URL(_codebase+_filename);
50 java.io.InputStream stream = ResourceLoader.openStream(url);
51 stream.close();
52 return true;
53 } catch(Exception exc) {
54 return false;
55 }
56 }
57 }
58
59 static public boolean fileExistsInJar(String _codebase, String _jarFile, String _filename) {
60 if((_filename==null)||(_jarFile==null)) {

Callers 1

parseConstantMethod · 0.95

Calls 7

fileExistsInJarMethod · 0.95
openStreamMethod · 0.95
existsMethod · 0.80
getMethod · 0.65
closeMethod · 0.65
getResourceMethod · 0.45
getClassLoaderMethod · 0.45

Tested by

no test coverage detected