Refactoring: Close property file handle after modify vm.
authorminkee.lee <minkee.lee@samsung.com>
Tue, 7 Oct 2014 07:22:50 +0000 (16:22 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Thu, 16 Oct 2014 12:23:52 +0000 (21:23 +0900)
Change-Id: I2c24e82a3a5da5c8738a3f11262eee5699a816bb
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
common-project/src/org/tizen/emulator/manager/vms/EmulatorVMList.java

index 8bfc448..170e425 100644 (file)
@@ -34,6 +34,7 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -221,6 +222,7 @@ public class EmulatorVMList {
                        outputFile = property.getPropertyFile();
                }
 
+               FileOutputStream fos = null;
                try {
                        Marshaller marshaller = context.createMarshaller();
                        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
@@ -230,15 +232,25 @@ public class EmulatorVMList {
                                property.getPropertyFile().getParentFile().mkdirs();
                        }
 
-                       marshaller.marshal(property.getConfiguration(), new FileOutputStream(outputFile));
+                       fos = new FileOutputStream(outputFile);
+                       marshaller.marshal(property.getConfiguration(), fos);
                } catch (JAXBException e) {
                        e.printStackTrace();
-
                        return false;
+
                } catch (FileNotFoundException e) {
                        e.printStackTrace();
-
                        return false;
+
+               } finally {
+                       if (fos != null) {
+                               try {
+                                       fos.close();
+                               } catch (IOException e) {
+                                       EMLogger.getLogger().warning("ERROR : " + e.getMessage());
+                                       return false;
+                               }
+                       }
                }
 
                return true;