Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-03-25 23:44:34 +0000
committerGreg Wilkins2015-03-26 01:18:06 +0000
commit7da5db8dc9e1b6a0a4683085cac7e5217ef66d24 (patch)
tree3fb1eefa696f058a76a2732e607f610582db7483
parenteca04f401af2a2c21bfea285175ab267e5614e9c (diff)
downloadorg.eclipse.jetty.project-7da5db8dc9e1b6a0a4683085cac7e5217ef66d24.tar.gz
org.eclipse.jetty.project-7da5db8dc9e1b6a0a4683085cac7e5217ef66d24.tar.xz
org.eclipse.jetty.project-7da5db8dc9e1b6a0a4683085cac7e5217ef66d24.zip
458478 - JarFileResource improve performance of exist method
Use JarFile.getJarEntry() rather than interation Also-by: alienisty@gmail.com Signed-off-by: gregw@intalio.com
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java59
1 files changed, 25 insertions, 34 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java
index 8decad8ae3..310df4a761 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java
@@ -179,40 +179,39 @@ class JarFileResource extends JarResource
}
catch(Exception e)
{
- LOG.ignore(e);
+ LOG.ignore(e);
}
}
// Do we need to look more closely?
if (jar_file!=null && _entry==null && !_directory)
{
- // OK - we have a JarFile, lets look at the entries for our path
- Enumeration<JarEntry> e=jar_file.entries();
- while(e.hasMoreElements())
+ // OK - we have a JarFile, lets look for the entry
+ JarEntry entry = jar_file.getJarEntry(_path);
+ if (entry == null)
{
- JarEntry entry = e.nextElement();
- String name=entry.getName().replace('\\','/');
-
- // Do we have a match
- if (name.equals(_path))
- {
- _entry=entry;
- // Is the match a directory
- _directory=_path.endsWith("/");
- break;
- }
- else if (_path.endsWith("/"))
+ // the entry does not exist
+ _exists = false;
+ }
+ else if (entry.isDirectory())
+ {
+ _directory = true;
+ _entry = entry;
+ }
+ else
+ {
+ // Let's confirm is a file
+ JarEntry directory = jar_file.getJarEntry(_path + '/');
+ if (directory != null)
{
- if (name.startsWith(_path))
- {
- _directory=true;
- break;
- }
- }
- else if (name.startsWith(_path) && name.length()>_path.length() && name.charAt(_path.length())=='/')
+ _directory = true;
+ _entry = directory;
+ }
+ else
{
- _directory=true;
- break;
+ // OK is a file
+ _directory = false;
+ _entry = entry;
}
}
}
@@ -228,7 +227,7 @@ class JarFileResource extends JarResource
LOG.ignore(ioe);
}
}
- }
+ }
_exists= ( _directory || _entry!=null);
return _exists;
@@ -418,11 +417,3 @@ class JarFileResource extends JarResource
return url.sameFile(resource.getURL());
}
}
-
-
-
-
-
-
-
-

Back to the top