Adds explicit encoding in KernelLoginModule, OvfPropertiesSource and KernelAuthenticationConfiguration
diff --git a/org.eclipse.virgo.nano.authentication/src/main/java/org/eclipse/virgo/nano/authentication/KernelLoginModule.java b/org.eclipse.virgo.nano.authentication/src/main/java/org/eclipse/virgo/nano/authentication/KernelLoginModule.java
index 2cb98d3..f945943 100644
--- a/org.eclipse.virgo.nano.authentication/src/main/java/org/eclipse/virgo/nano/authentication/KernelLoginModule.java
+++ b/org.eclipse.virgo.nano.authentication/src/main/java/org/eclipse/virgo/nano/authentication/KernelLoginModule.java
@@ -11,8 +11,11 @@
package org.eclipse.virgo.nano.authentication;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.io.FileInputStream;
import java.io.IOException;
-import java.io.FileReader;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Map;
import java.util.Properties;
@@ -116,22 +119,12 @@
this.getClass().getCanonicalName()));
}
- Reader reader = null;
- try {
- reader = new FileReader(fileLocation);
+ try (Reader reader = new InputStreamReader(new FileInputStream(fileLocation), UTF_8)) {
Properties properties = new Properties();
properties.load(reader);
return properties;
} catch (IOException e) {
throw new IllegalArgumentException(String.format("Unable to load properties file from '%s'", fileLocation), e);
- } finally {
- if(reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- // Nothing to do here
- }
- }
}
}
}
diff --git a/org.eclipse.virgo.nano.core/src/main/java/org/eclipse/virgo/nano/config/internal/ovf/OvfPropertiesSource.java b/org.eclipse.virgo.nano.core/src/main/java/org/eclipse/virgo/nano/config/internal/ovf/OvfPropertiesSource.java
index 1cacc26..8e2a645 100644
--- a/org.eclipse.virgo.nano.core/src/main/java/org/eclipse/virgo/nano/config/internal/ovf/OvfPropertiesSource.java
+++ b/org.eclipse.virgo.nano.core/src/main/java/org/eclipse/virgo/nano/config/internal/ovf/OvfPropertiesSource.java
@@ -11,22 +11,23 @@
package org.eclipse.virgo.nano.config.internal.ovf;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.virgo.nano.diagnostics.KernelLogEvents.OVF_CONFIGURATION_FILE_DOES_NOT_EXIST;
+import static org.eclipse.virgo.nano.diagnostics.KernelLogEvents.OVF_READ_ERROR;
+
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import org.osgi.framework.BundleContext;
-
-
import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.nano.config.internal.PropertiesSource;
-import org.eclipse.virgo.nano.diagnostics.KernelLogEvents;
-import org.eclipse.virgo.util.io.IOUtils;
+import org.osgi.framework.BundleContext;
/**
* Implementation of {@link PropertiesSource} that reads properties from an OVF document.
@@ -123,7 +124,7 @@
File ovfFile = determineOvfFile();
if (ovfFile != null) {
if (!ovfFile.exists()) {
- this.eventLogger.log(KernelLogEvents.OVF_CONFIGURATION_FILE_DOES_NOT_EXIST, ovfFile.getAbsolutePath());
+ this.eventLogger.log(OVF_CONFIGURATION_FILE_DOES_NOT_EXIST, ovfFile.getAbsolutePath());
} else {
result = readOvfFile(ovfFile);
}
@@ -145,15 +146,11 @@
private Properties readOvfFile(File ovfFile) {
Properties result = null;
- Reader reader = null;
- try {
- reader = new FileReader(ovfFile);
+ try (Reader reader = new InputStreamReader(new FileInputStream(ovfFile), UTF_8)) {
OvfEnvironmentPropertiesReader ovfReader = new OvfEnvironmentPropertiesReader();
result = ovfReader.readProperties(reader);
} catch (IOException ex) {
- this.eventLogger.log(KernelLogEvents.OVF_READ_ERROR, ex, ovfFile.getAbsolutePath());
- } finally {
- IOUtils.closeQuietly(reader);
+ this.eventLogger.log(OVF_READ_ERROR, ex, ovfFile.getAbsolutePath());
}
return result;
}
diff --git a/org.eclipse.virgo.nano.shutdown/src/main/java/org/eclipse/virgo/nano/shutdown/KernelAuthenticationConfiguration.java b/org.eclipse.virgo.nano.shutdown/src/main/java/org/eclipse/virgo/nano/shutdown/KernelAuthenticationConfiguration.java
index b7b78c9..2c66ec7 100644
--- a/org.eclipse.virgo.nano.shutdown/src/main/java/org/eclipse/virgo/nano/shutdown/KernelAuthenticationConfiguration.java
+++ b/org.eclipse.virgo.nano.shutdown/src/main/java/org/eclipse/virgo/nano/shutdown/KernelAuthenticationConfiguration.java
@@ -13,8 +13,11 @@
package org.eclipse.virgo.nano.shutdown;
-import java.io.FileReader;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Properties;
@@ -81,22 +84,12 @@
return null;
}
- Reader reader = null;
- try {
- reader = new FileReader(fileLocation);
+ try (Reader reader = new InputStreamReader(new FileInputStream(fileLocation), UTF_8)) {
Properties properties = new Properties();
properties.load(reader);
return properties;
} catch (IOException e) {
return null;
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- // Nothing to do here
- }
- }
}
}