fixed closure of streams
diff --git a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/JarResources.java b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/JarResources.java
index 2e96c3c..3f45575 100644
--- a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/JarResources.java
+++ b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/JarResources.java
@@ -5,8 +5,8 @@
import java.util.zip.*;
/**
- * JarResources: JarResources maps all resources included in a Zip or Jar file.
- * Additionaly, it provides a method to extract one as a blob.
+ * JarResources: JarResources maps all resources included in a Zip or Jar file. Additionaly, it provides a method to
+ * extract one as a blob.
*
* <p>
* CREDITS
@@ -30,8 +30,7 @@
private String jarFileName;
/**
- * creates a JarResources. It extracts all resources from a Jar into an
- * internal hashtable, keyed by resource names.
+ * creates a JarResources. It extracts all resources from a Jar into an internal hashtable, keyed by resource names.
*
* @param jarFileName
* a jar or zip file
@@ -79,8 +78,7 @@
}
if (debugOn) {
- System.out.println("ze.getName()=" + ze.getName() + ","
- + "getSize()=" + ze.getSize());
+ System.out.println("ze.getName()=" + ze.getName() + "," + "getSize()=" + ze.getSize());
}
int size = (int) ze.getSize();
@@ -104,10 +102,11 @@
htJarContents.put(ze.getName(), b);
if (debugOn) {
- System.out.println(ze.getName() + " rb=" + rb + ",size="
- + size + ",csize=" + ze.getCompressedSize());
+ System.out.println(ze.getName() + " rb=" + rb + ",size=" + size + ",csize="
+ + ze.getCompressedSize());
}
}
+ zis.close();
} catch (NullPointerException e) {
System.out.println("done.");
} catch (FileNotFoundException e) {
@@ -148,12 +147,11 @@
}
/**
- * Is a test driver. Given a jar file and a resource name, it trys to
- * extract the resource and then tells us whether it could or not.
+ * Is a test driver. Given a jar file and a resource name, it trys to extract the resource and then tells us whether
+ * it could or not.
*
- * <strong>Example</strong> Let's say you have a JAR file which jarred up a
- * bunch of gif image files. Now, by using JarResources, you could extract,
- * create, and display those images on-the-fly.
+ * <strong>Example</strong> Let's say you have a JAR file which jarred up a bunch of gif image files. Now, by using
+ * JarResources, you could extract, create, and display those images on-the-fly.
*
* <pre>
* ...
@@ -167,8 +165,7 @@
*/
public static void main(String[] args) throws IOException {
if (args.length != 2) {
- System.err
- .println("usage: java JarResources <jar file name> <resource name>");
+ System.err.println("usage: java JarResources <jar file name> <resource name>");
System.exit(1);
}
@@ -177,8 +174,7 @@
if (buff == null) {
System.out.println("Could not find " + args[1] + ".");
} else {
- System.out.println("Found " + args[1] + " (length=" + buff.length
- + ").");
+ System.out.println("Found " + args[1] + " (length=" + buff.length + ").");
}
}
diff --git a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/TestClassLoader.java b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/TestClassLoader.java
index 4fe08e1..2dfeeb4 100644
--- a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/TestClassLoader.java
+++ b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/TestClassLoader.java
@@ -1,14 +1,15 @@
package org.apache.s4.base.util;
import java.io.FileInputStream;
+import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestClassLoader extends MultiClassLoader {
- private static final Logger logger = LoggerFactory
- .getLogger(TestClassLoader.class);
+ private static final Logger logger = LoggerFactory.getLogger(TestClassLoader.class);
+
@Override
/** Simple method to read a class file from a known location. */
public byte[] loadClassBytes(String className) {
@@ -17,22 +18,29 @@
String filename = "/tmp/" + className + ".impl";
logger.debug("Reading: " + filename);
+ FileInputStream fi = null;
try {
- FileInputStream fi = new FileInputStream(filename);
+ fi = new FileInputStream(filename);
bytes = new byte[fi.available()];
fi.read(bytes);
return bytes;
} catch (Exception e) {
/*
- * If we caught an exception, either the class wasn't found or it
- * was unreadable by our process.
+ * If we caught an exception, either the class wasn't found or it was unreadable by our process.
*/
logger.error("Unable to load class: {}.", filename);
e.printStackTrace();
return null;
+ } finally {
+ if (fi != null) {
+ try {
+ fi.close();
+ } catch (IOException e) {
+ logger.warn("Exception while closing input stream", e);
+ }
+ }
}
}
-
}