From 06fafbe28c7c90712bbb10831e1af1c4f4dcaa4f Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Tue, 12 Jan 2010 14:21:27 +0000
Subject: [PATCH] Not loading properties file with Properties.load() method in
 order to avoid property values like 'E:\users\Johan' to be interpreted as
 Unicode escape sequences.

SVN: 14252
---
 .../DataSetInfoExtractorForMSInjection.java   | 37 +++++++++++++------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/phosphonetx/DataSetInfoExtractorForMSInjection.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/phosphonetx/DataSetInfoExtractorForMSInjection.java
index 3f9e55abef8..890acfeaa12 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/phosphonetx/DataSetInfoExtractorForMSInjection.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/phosphonetx/DataSetInfoExtractorForMSInjection.java
@@ -30,6 +30,7 @@ import org.apache.commons.io.IOUtils;
 import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
 import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
 import ch.systemsx.cisd.common.exceptions.UserFailureException;
+import ch.systemsx.cisd.common.filesystem.FileUtilities;
 import ch.systemsx.cisd.common.utilities.ITimeProvider;
 import ch.systemsx.cisd.common.utilities.PropertyUtils;
 import ch.systemsx.cisd.common.utilities.SystemTimeProvider;
@@ -157,7 +158,6 @@ public class DataSetInfoExtractorForMSInjection implements IDataSetInfoExtractor
     
     private Properties loadMSInjectionProperties(File incomingDataSetDirectory)
     {
-        Properties msInjectionProperties = new Properties();
         File msInjectionPropertiesFile =
                 new File(incomingDataSetDirectory, msInjectionPropertiesFileName);
         if (msInjectionPropertiesFile.exists() == false)
@@ -170,18 +170,31 @@ public class DataSetInfoExtractorForMSInjection implements IDataSetInfoExtractor
             throw new UserFailureException("Properties file '" + msInjectionPropertiesFileName
                     + "' is a folder.");
         }
-        FileInputStream stream = null;
-        try
-        {
-            stream = new FileInputStream(msInjectionPropertiesFile);
-            msInjectionProperties.load(stream);
-        } catch (IOException ex)
-        {
-            throw CheckedExceptionTunnel.wrapIfNecessary(ex);
-        } finally
+        return loadPropertiesFile(msInjectionPropertiesFile);
+    }
+
+    private Properties loadPropertiesFile(File msInjectionPropertiesFile)
+    {
+        Properties properties = new Properties();
+        List<String> lines = FileUtilities.loadToStringList(msInjectionPropertiesFile);
+        for (int i = 0; i < lines.size(); i++)
         {
-            IOUtils.closeQuietly(stream);
+            String line = lines.get(i);
+            if (line.length() == 0 || line.startsWith("#"))
+            {
+                continue;
+            }
+            int indexOfEqualSymbol = line.indexOf('=');
+            if (indexOfEqualSymbol < 0)
+            {
+                throw new UserFailureException("Missing '=' in line " + (i + 1)
+                        + " of MS injection properties file " + msInjectionPropertiesFileName
+                        + ": " + line);
+            }
+            String key = line.substring(0, indexOfEqualSymbol).trim();
+            String value = line.substring(indexOfEqualSymbol + 1).trim();
+            properties.setProperty(key, value);
         }
-        return msInjectionProperties;
+        return properties;
     }
 }
-- 
GitLab