KARAF-5879 - Close input and output streams in CaveFeatureGateway/Test. (#11)
authorBob Paulin <bob@bobpaulin.com>
Tue, 28 Aug 2018 13:15:10 +0000 (08:15 -0500)
committerJean-Baptiste Onofré <jbonofre@apache.org>
Tue, 28 Aug 2018 13:15:10 +0000 (15:15 +0200)
[KARAF-5879]  Close input and output streams in CaveFeatureGateway/Test.

server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImpl.java
server/storage/src/test/java/org/apache/karaf/cave/server/storage/CaveFeatureGatewayImplTest.java

index 0d2bd76..3a39166 100644 (file)
@@ -21,6 +21,7 @@ import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.JaxbUtil;
 
 import java.io.File;
+import java.io.OutputStream;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -43,7 +44,8 @@ public class CaveFeatureGatewayImpl implements CaveFeatureGateway {
             throw new IllegalArgumentException("Features repository " + url + " already registered in the gateway");
         }
         features.getRepository().add(url);
-        JaxbUtil.marshal(features, new FileOutputStream(storage));
+        
+        marshalStorageFile(storage, features);
     }
 
     @Override
@@ -59,7 +61,8 @@ public class CaveFeatureGatewayImpl implements CaveFeatureGateway {
             throw new IllegalArgumentException("Features repository " + url + " is not registered in the gateway");
         }
         features.getRepository().remove(url);
-        JaxbUtil.marshal(features, new FileOutputStream(storage));
+        
+        marshalStorageFile(storage, features);
     }
 
     @Override
@@ -83,4 +86,11 @@ public class CaveFeatureGatewayImpl implements CaveFeatureGateway {
         }
         return false;
     }
+    
+    private void marshalStorageFile(File storage, Features features)
+                       throws Exception {
+        OutputStream storageFileOs = new FileOutputStream(storage);
+        JaxbUtil.marshal(features, storageFileOs);
+        storageFileOs.close();
+       }
 }
index b6d8c7f..d1eea29 100644 (file)
@@ -73,6 +73,7 @@ public class CaveFeatureGatewayImplTest {
         while ((line = reader.readLine()) != null) {
             builder.append(line);
         }
+        reader.close();
         return builder.toString();
     }