Cleanup (formatting)

This commit is contained in:
Roman Shevchenko
2016-07-20 14:56:09 +02:00
parent e01291e91c
commit 2e9a30ee58
@@ -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();
}
}
}
}