diff options
author | Alexander Kurtakov | 2018-10-09 06:23:43 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2018-10-09 06:23:43 +0000 |
commit | 85ebd007c251b6a7e06624c94314979f5ca0b927 (patch) | |
tree | 60434d0f02287ad8b0ebe971d141668dbf111ba7 | |
parent | 4950af2c2805829d3dafbc12363036365c00ee22 (diff) | |
download | rt.equinox.bundles-85ebd007c251b6a7e06624c94314979f5ca0b927.tar.gz rt.equinox.bundles-85ebd007c251b6a7e06624c94314979f5ca0b927.tar.xz rt.equinox.bundles-85ebd007c251b6a7e06624c94314979f5ca0b927.zip |
Use try-with-resources in equinox.app.I20181009-0600
Change-Id: I58121f71682347d49f3a5a19f9ddc96b7594b0a4
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r-- | bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java index a34964ed1..4e4b67255 100644 --- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java +++ b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistence.java @@ -242,9 +242,8 @@ public class AppPersistence implements ServiceTrackerCustomizer { } private static void loadLocks(File locksData) throws IOException { - ObjectInputStream in = null; - try { - in = new ObjectInputStream(new FileInputStream(locksData)); + try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(locksData));) { + int dataVersion = in.readInt(); if (dataVersion != DATA_VERSION) return; @@ -253,16 +252,11 @@ public class AppPersistence implements ServiceTrackerCustomizer { for (int i = 0; i < numLocks; i++) locks.add(in.readUTF()); } - } finally { - if (in != null) - in.close(); } } private static void loadSchedules(File schedulesData) throws IOException { - ObjectInputStream in = null; - try { - in = new ObjectInputStream(new FileInputStream(schedulesData)); + try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(schedulesData))) { int dataVersion = in.readInt(); if (dataVersion != DATA_VERSION) return; @@ -283,9 +277,6 @@ public class AppPersistence implements ServiceTrackerCustomizer { throw new IOException(e.getMessage()); } catch (ClassNotFoundException e) { throw new IOException(e.getMessage()); - } finally { - if (in != null) - in.close(); } } @@ -307,24 +298,16 @@ public class AppPersistence implements ServiceTrackerCustomizer { // must call this while holding the locks lock private static void saveLocks(File locksData) throws IOException { - ObjectOutputStream out = null; - try { - out = new ObjectOutputStream(new FileOutputStream(locksData)); - out.writeInt(DATA_VERSION); + try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(locksData))) { out.writeInt(locks.size()); for (Iterator iterLocks = locks.iterator(); iterLocks.hasNext();) out.writeUTF((String) iterLocks.next()); - } finally { - if (out != null) - out.close(); } } // must call this while holding the scheduledApps lock private static void saveSchedules(File schedulesData) throws IOException { - ObjectOutputStream out = null; - try { - out = new ObjectOutputStream(new FileOutputStream(schedulesData)); + try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(schedulesData))) { out.writeInt(DATA_VERSION); out.writeInt(scheduledApps.size()); for (Iterator apps = scheduledApps.values().iterator(); apps.hasNext();) { @@ -336,9 +319,6 @@ public class AppPersistence implements ServiceTrackerCustomizer { out.writeBoolean(app.isRecurring()); out.writeObject(app.getArguments()); } - } finally { - if (out != null) - out.close(); } } |