svn commit: r13291 - trunk/src_new/org/argouml/persistence/UmlFilePersister.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-08-09 18:30:35-0700
New Revision: 13291

Modified:
   trunk/src_new/org/argouml/persistence/UmlFilePersister.java

Log:
Make sure input streams get closed.  Bump default version to 1 from 0.

Modified: trunk/src_new/org/argouml/persistence/UmlFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/persistence/UmlFilePersister.java?view=diff&rev=13291&p1=trunk/src_new/org/argouml/persistence/UmlFilePersister.java&p2=trunk/src_new/org/argouml/persistence/UmlFilePersister.java&r1=13290&r2=13291
==============================================================================
--- trunk/src_new/org/argouml/persistence/UmlFilePersister.java	(original)
+++ trunk/src_new/org/argouml/persistence/UmlFilePersister.java	2007-08-09 18:30:35-0700
@@ -509,13 +509,25 @@
      * @throws OpenException on any error
      */
     private int getPersistenceVersionFromFile(File file) throws OpenException {
+        InputStream stream = null;
         try {
-            return getPersistenceVersion(new BufferedInputStream(file.toURL()
-                    .openStream()));
+            stream = new BufferedInputStream(file.toURL()
+                    .openStream());
+            int version = getPersistenceVersion(stream);
+            stream.close();
+            return version;
         } catch (MalformedURLException e) {
             throw new OpenException(e);
         } catch (IOException e) {
             throw new OpenException(e);
+        } finally {
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
         }
     }
         
@@ -537,7 +549,7 @@
                 rootLine = reader.readLine();
             }
             if (rootLine == null) {
-                return 0;
+                return 1;
             }
             return Integer.parseInt(getVersion(rootLine));
         } catch (IOException e) {
@@ -564,13 +576,24 @@
      * @throws OpenException on any error
      */
     private String getReleaseVersionFromFile(File file) throws OpenException {
+        InputStream stream = null;
         try {
-            return getReleaseVersion(new BufferedInputStream(file.toURL()
-                    .openStream()));
+            stream = new BufferedInputStream(file.toURL().openStream());
+            String version = getReleaseVersion(stream);
+            stream.close();
+            return version;
         } catch (MalformedURLException e) {
             throw new OpenException(e);
         } catch (IOException e) {
             throw new OpenException(e);
+        } finally {
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.