Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMahdi Ben Alaya2018-07-02 09:32:33 -0400
committerGerrit Code Review @ Eclipse.org2018-07-02 09:32:33 -0400
commite448592e40e04e6678e2af772dd142e395a061c5 (patch)
treecd552262ad4c9189bd12b7c944875f93c88bcd41
parentc83c48a7eadcd58d380b2757677b93a84fb88ceb (diff)
parent23ead43c8cad0458a3609d32f640c79627f1360f (diff)
downloadorg.eclipse.om2m-e448592e40e04e6678e2af772dd142e395a061c5.tar.gz
org.eclipse.om2m-e448592e40e04e6678e2af772dd142e395a061c5.tar.xz
org.eclipse.om2m-e448592e40e04e6678e2af772dd142e395a061c5.zip
Merge "hue.basedriver: use Properties to load & update configuration file" into dev
-rw-r--r--protocols/org.eclipse.om2m.protocols.hue/org.eclipse.om2m.hue.impl/src/main/java/org/eclipse/om2m/hue/impl/HueBasedriver.java25
1 files changed, 9 insertions, 16 deletions
diff --git a/protocols/org.eclipse.om2m.protocols.hue/org.eclipse.om2m.hue.impl/src/main/java/org/eclipse/om2m/hue/impl/HueBasedriver.java b/protocols/org.eclipse.om2m.protocols.hue/org.eclipse.om2m.hue.impl/src/main/java/org/eclipse/om2m/hue/impl/HueBasedriver.java
index 21a3ed9a..5263b1d7 100644
--- a/protocols/org.eclipse.om2m.protocols.hue/org.eclipse.om2m.hue.impl/src/main/java/org/eclipse/om2m/hue/impl/HueBasedriver.java
+++ b/protocols/org.eclipse.om2m.protocols.hue/org.eclipse.om2m.hue.impl/src/main/java/org/eclipse/om2m/hue/impl/HueBasedriver.java
@@ -17,6 +17,7 @@ package org.eclipse.om2m.hue.impl;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -33,6 +34,7 @@ import java.util.Dictionary;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
+import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
@@ -457,23 +459,14 @@ public class HueBasedriver implements ManagedService {
protected void updatePropertiesFile(String filename, String key, String value) {
try {
File file = new File("configurations/services/" + filename);
- Logger.info("Updating the: " + filename + " file, to save the: " + key + " property");
+ Properties properties = new Properties();
FileReader fr = new FileReader(file);
- BufferedReader br = new BufferedReader(fr);
- ArrayList<String> lines = new ArrayList<String>();
- String line = br.readLine();
- while (line != null) {
- if (line.contains(key)) {
- line = key + " " + value;
- }
- lines.add(line);
- line = br.readLine();
- }
- fr.close();
- FileWriter fw = new FileWriter(file);
- BufferedWriter out = new BufferedWriter(fw);
- out.write(lines.toString().replace("[", "").replace("]", "").replace(", ", "\n"));
- out.close();
+ properties.load(fr);
+
+ Logger.info("Updating the: " + filename + " file, to save the: " + key + " property");
+ properties.setProperty(key, value);
+ properties.store(new FileOutputStream(file), "");
+
}
catch (IOException e) {
Logger.error("Error while updating the: " + filename + " file, to save the: " + key + " property", e);

Back to the top