Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Mazursky2013-08-28 03:58:56 +0000
committerGerrit Code Review @ Eclipse.org2013-09-09 04:24:31 +0000
commit767faece5c4692748d1ac8e130b2e4c5faa1ff20 (patch)
tree787e93c5bf452b69d28d737a04d57cddae0b7ede /jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java
parentcdd95bb5515f35af090bcbcf6f9af03d5c6762c9 (diff)
downloadorg.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.tar.gz
org.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.tar.xz
org.eclipse.jetty.project-767faece5c4692748d1ac8e130b2e4c5faa1ff20.zip
[Bug 415999] Fix some of FindBugs warnings
Mostly not closed streams/DB resources are fixed. But also less important things. Signed-off-by: Mikhail Mazursky <mikhail.mazursky@gmail.com>
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

Back to the top