src/share/classes/sun/rmi/log/ReliableLog.java

Print this page

        

@@ -342,14 +342,13 @@
                         new PrivilegedAction<ClassLoader>() {
                             public ClassLoader run() {
                                return ClassLoader.getSystemClassLoader();
                             }
                         });
-                Class cl = loader.loadClass(logClassName);
-                if (LogFile.class.isAssignableFrom(cl)) {
+                Class<? extends LogFile> cl = 
+                    loader.loadClass(logClassName).asSubclass(LogFile.class);
                     return cl.getConstructor(String.class, String.class);
-                }
             } catch (Exception e) {
                 System.err.println("Exception occurred:");
                 e.printStackTrace();
             }
         }

@@ -593,15 +592,15 @@
         if (newVersion) {
             name = newVersionFile;
         } else {
             name = versionFile;
         }
-        DataOutputStream out =
-            new DataOutputStream(new FileOutputStream(fName(name)));
+        try (FileOutputStream fos = new FileOutputStream(fName(name));
+             DataOutputStream out = new DataOutputStream(fos)) {
         writeInt(out, version);
-        out.close();
     }
+    }
 
     /**
      * Creates the initial version file
      *
      * @exception IOException If an I/O error has occurred.

@@ -627,15 +626,13 @@
      * @param name the name of the version file
      * @return the version
      * @exception IOException If an I/O error has occurred.
      */
     private int readVersion(String name) throws IOException {
-        DataInputStream in = new DataInputStream(new FileInputStream(name));
-        try {
+        try (FileInputStream fis = new FileInputStream(name);
+             DataInputStream in = new DataInputStream(fis)) {
             return in.readInt();
-        } finally {
-            in.close();
         }
     }
 
     /**
      * Sets the version.  If version file does not exist, the initial