From 2e9a30ee5874b48403cea2cde6d7563708332d24 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 20 Jul 2016 14:54:40 +0200 Subject: [PATCH] Cleanup (formatting) --- .../application/PermanentInstallationID.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/PermanentInstallationID.java b/platform/platform-impl/src/com/intellij/openapi/application/PermanentInstallationID.java index 8eab31d0a9e3..44c3c094a1a5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/PermanentInstallationID.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/PermanentInstallationID.java @@ -17,6 +17,7 @@ package com.intellij.openapi.application; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtilRt; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; import org.jetbrains.annotations.NotNull; @@ -32,6 +33,7 @@ public class PermanentInstallationID { private static final String INSTALLATION_ID_KEY = "user_id_on_machine"; private static final String INSTALLATION_ID = calculateInstallationId(); + @NotNull public static String get() { return INSTALLATION_ID; } @@ -42,8 +44,8 @@ public class PermanentInstallationID { final Preferences prefs = Preferences.userRoot().node("jetbrains"); String installationId = prefs.get(INSTALLATION_ID_KEY, null); - if (installationId == null || installationId.isEmpty()) { - installationId = oldValue != null && !oldValue.isEmpty() ? oldValue : UUID.randomUUID().toString(); + if (StringUtil.isEmpty(installationId)) { + installationId = !StringUtil.isEmpty(oldValue) ? oldValue : UUID.randomUUID().toString(); prefs.put(INSTALLATION_ID_KEY, installationId); } @@ -69,8 +71,7 @@ public class PermanentInstallationID { writeToFile(permanentIdFile, installationId); } } - catch (IOException ignored) { - } + catch (IOException ignored) { } } } } @@ -85,25 +86,16 @@ public class PermanentInstallationID { @NotNull private static String loadFromFile(@NotNull File file) throws IOException { - final FileInputStream is = new FileInputStream(file); - try { + try (FileInputStream is = new FileInputStream(file)) { final byte[] bytes = FileUtilRt.loadBytes(is); final int offset = CharsetToolkit.hasUTF8Bom(bytes) ? CharsetToolkit.UTF8_BOM.length : 0; return new String(bytes, offset, bytes.length - offset, CharsetToolkit.UTF8_CHARSET); } - finally { - is.close(); - } } private static void writeToFile(@NotNull File file, @NotNull String text) throws IOException { - final DataOutputStream stream = new DataOutputStream(new FileOutputStream(file)); - try { + try (DataOutputStream stream = new DataOutputStream(new FileOutputStream(file))) { stream.write(text.getBytes(CharsetToolkit.UTF8_CHARSET)); } - finally { - stream.close(); - } } - -} +} \ No newline at end of file