Author: cmueller
Date: Mon Apr 9 21:16:31 2012
New Revision: 1311454
URL: http://svn.apache.org/viewvc?rev=1311454&view=rev
Log:
make sure the used Input- and OutputSreams are closed in case an exception
occurs
Modified:
camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
Modified:
camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java?rev=1311454&r1=1311453&r2=1311454&view=diff
==============================================================================
---
camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
(original)
+++
camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
Mon Apr 9 21:16:31 2012
@@ -20,6 +20,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@@ -242,22 +243,29 @@ public abstract class CamelBlueprintTest
private BundleDescriptor getBundleDescriptor(String path, TinyBundle
bundle) throws Exception {
File file = new File(path);
FileOutputStream fos = new FileOutputStream(file, true);
- IOHelper.copy(bundle.build(), fos);
- IOHelper.close(fos);
+ try {
+ IOHelper.copy(bundle.build(), fos);
+ } finally {
+ IOHelper.close(fos);
+ }
+
+ FileInputStream fis = null;
+ JarInputStream jis = null;
+ try {
+ fis = new FileInputStream(file);
+ jis = new JarInputStream(fis);
+ Map<String, String> headers = new HashMap<String, String>();
+ for (Map.Entry<Object, Object> entry :
jis.getManifest().getMainAttributes().entrySet()) {
+ headers.put(entry.getKey().toString(),
entry.getValue().toString());
+ }
- FileInputStream fis = new FileInputStream(file);
- JarInputStream jis = new JarInputStream(fis);
- Map<String, String> headers = new HashMap<String, String>();
- for (Map.Entry<Object, Object> entry :
jis.getManifest().getMainAttributes().entrySet()) {
- headers.put(entry.getKey().toString(),
entry.getValue().toString());
- }
-
- IOHelper.close(fis, jis);
-
- return new BundleDescriptor(
- getClass().getClassLoader(),
- new URL("jar:" + file.toURI().toString() + "!/"),
- headers);
+ return new BundleDescriptor(
+ getClass().getClassLoader(),
+ new URL("jar:" + file.toURI().toString() + "!/"),
+ headers);
+ } finally {
+ IOHelper.close(fis, jis);
+ }
}
}