aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java')
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java178
1 files changed, 87 insertions, 91 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java
index fe9dbb44e2..c0cfc281e0 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.jar.JarEntry;
@@ -153,115 +154,110 @@ public class JarResource extends URLResource
if (LOG.isDebugEnabled())
LOG.debug("Extracting entry = "+subEntryName+" from jar "+jarFileURL);
- InputStream is = jarFileURL.openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is);
- JarEntry entry;
- boolean shouldExtract;
- while((entry=jin.getNextJarEntry())!=null)
+ try (InputStream is = jarFileURL.openConnection().getInputStream();
+ JarInputStream jin = new JarInputStream(is))
{
- String entryName = entry.getName();
- if ((subEntryName != null) && (entryName.startsWith(subEntryName)))
- {
- // is the subentry really a dir?
- if (!subEntryIsDir && subEntryName.length()+1==entryName.length() && entryName.endsWith("/"))
- subEntryIsDir=true;
-
- //if there is a particular subEntry that we are looking for, only
- //extract it.
- if (subEntryIsDir)
+ JarEntry entry;
+ boolean shouldExtract;
+ while((entry=jin.getNextJarEntry())!=null)
+ {
+ String entryName = entry.getName();
+ if ((subEntryName != null) && (entryName.startsWith(subEntryName)))
{
- //if it is a subdirectory we are looking for, then we
- //are looking to extract its contents into the target
- //directory. Remove the name of the subdirectory so
- //that we don't wind up creating it too.
- entryName = entryName.substring(subEntryName.length());
- if (!entryName.equals(""))
+ // is the subentry really a dir?
+ if (!subEntryIsDir && subEntryName.length()+1==entryName.length() && entryName.endsWith("/"))
+ subEntryIsDir=true;
+
+ //if there is a particular subEntry that we are looking for, only
+ //extract it.
+ if (subEntryIsDir)
{
- //the entry is
- shouldExtract = true;
+ //if it is a subdirectory we are looking for, then we
+ //are looking to extract its contents into the target
+ //directory. Remove the name of the subdirectory so
+ //that we don't wind up creating it too.
+ entryName = entryName.substring(subEntryName.length());
+ if (!entryName.equals(""))
+ {
+ //the entry is
+ shouldExtract = true;
+ }
+ else
+ shouldExtract = false;
}
else
- shouldExtract = false;
+ shouldExtract = true;
+ }
+ else if ((subEntryName != null) && (!entryName.startsWith(subEntryName)))
+ {
+ //there is a particular entry we are looking for, and this one
+ //isn't it
+ shouldExtract = false;
}
else
- shouldExtract = true;
- }
- else if ((subEntryName != null) && (!entryName.startsWith(subEntryName)))
- {
- //there is a particular entry we are looking for, and this one
- //isn't it
- shouldExtract = false;
- }
- else
- {
- //we are extracting everything
- shouldExtract = true;
- }
-
-
- if (!shouldExtract)
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Skipping entry: "+entryName);
- continue;
- }
-
- String dotCheck = entryName.replace('\\', '/');
- dotCheck = URIUtil.canonicalPath(dotCheck);
- if (dotCheck == null)
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Invalid entry: "+entryName);
- continue;
- }
+ {
+ //we are extracting everything
+ shouldExtract = true;
+ }
- File file=new File(directory,entryName);
-
- if (entry.isDirectory())
- {
- // Make directory
- if (!file.exists())
- file.mkdirs();
- }
- else
- {
- // make directory (some jars don't list dirs)
- File dir = new File(file.getParent());
- if (!dir.exists())
- dir.mkdirs();
+ if (!shouldExtract)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Skipping entry: "+entryName);
+ continue;
+ }
- // Make file
- FileOutputStream fout = null;
- try
+ String dotCheck = entryName.replace('\\', '/');
+ dotCheck = URIUtil.canonicalPath(dotCheck);
+ if (dotCheck == null)
{
- fout = new FileOutputStream(file);
- IO.copy(jin,fout);
+ if (LOG.isDebugEnabled())
+ LOG.debug("Invalid entry: "+entryName);
+ continue;
}
- finally
+
+ File file=new File(directory,entryName);
+
+ if (entry.isDirectory())
{
- IO.close(fout);
+ // Make directory
+ if (!file.exists())
+ file.mkdirs();
}
+ else
+ {
+ // make directory (some jars don't list dirs)
+ File dir = new File(file.getParent());
+ if (!dir.exists())
+ dir.mkdirs();
+
+ // Make file
+ try (OutputStream fout = new FileOutputStream(file))
+ {
+ IO.copy(jin,fout);
+ }
- // touch the file.
- if (entry.getTime()>=0)
- file.setLastModified(entry.getTime());
+ // touch the file.
+ if (entry.getTime()>=0)
+ file.setLastModified(entry.getTime());
+ }
}
- }
-
- if ((subEntryName == null) || (subEntryName != null && subEntryName.equalsIgnoreCase("META-INF/MANIFEST.MF")))
- {
- Manifest manifest = jin.getManifest();
- if (manifest != null)
+
+ if ((subEntryName == null) || (subEntryName != null && subEntryName.equalsIgnoreCase("META-INF/MANIFEST.MF")))
{
- File metaInf = new File (directory, "META-INF");
- metaInf.mkdir();
- File f = new File(metaInf, "MANIFEST.MF");
- FileOutputStream fout = new FileOutputStream(f);
- manifest.write(fout);
- fout.close();
+ Manifest manifest = jin.getManifest();
+ if (manifest != null)
+ {
+ File metaInf = new File (directory, "META-INF");
+ metaInf.mkdir();
+ File f = new File(metaInf, "MANIFEST.MF");
+ try (OutputStream fout = new FileOutputStream(f))
+ {
+ manifest.write(fout);
+ }
+ }
}
}
- IO.close(jin);
}
public static Resource newJarResource(Resource resource) throws IOException