Merge branch 'develop' into features/JAL-4219_extended_fasta_rna_ss
[jalview.git] / getdown / src / getdown / core / src / main / java / com / threerings / getdown / util / Config.java
index c7e2933..6681c35 100644 (file)
@@ -5,9 +5,13 @@
 
 package com.threerings.getdown.util;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.MalformedURLException;
@@ -174,38 +178,73 @@ public class Config
      * one key/value pair in the config file was associated with the same key.
      */
     public static Config parseConfig (File source, ParseOpts opts)
-        throws IOException
-    {
-        Map<String, Object> data = new HashMap<>();
-
-        // I thought that we could use HashMap<String, String[]> and put new String[] {pair[1]} for
-        // the null case, but it mysteriously dies on launch, so leaving it as HashMap<String,
-        // Object> for now
-        for (String[] pair : parsePairs(source, opts)) {
-            Object value = data.get(pair[0]);
-            if (value == null) {
-                data.put(pair[0], pair[1]);
-            } else if (value instanceof String) {
-                data.put(pair[0], new String[] { (String)value, pair[1] });
-            } else if (value instanceof String[]) {
-                String[] values = (String[])value;
-                String[] nvalues = new String[values.length+1];
-                System.arraycopy(values, 0, nvalues, 0, values.length);
-                nvalues[values.length] = pair[1];
-                data.put(pair[0], nvalues);
+            throws IOException
+        {
+            Map<String, Object> data = new HashMap<>();
+
+            // I thought that we could use HashMap<String, String[]> and put new String[] {pair[1]} for
+            // the null case, but it mysteriously dies on launch, so leaving it as HashMap<String,
+            // Object> for now
+            for (String[] pair : parsePairs(source, opts)) {
+                Object value = data.get(pair[0]);
+                if (value == null) {
+                    data.put(pair[0], pair[1]);
+                } else if (value instanceof String) {
+                    data.put(pair[0], new String[] { (String)value, pair[1] });
+                } else if (value instanceof String[]) {
+                    String[] values = (String[])value;
+                    String[] nvalues = new String[values.length+1];
+                    System.arraycopy(values, 0, nvalues, 0, values.length);
+                    nvalues[values.length] = pair[1];
+                    data.put(pair[0], nvalues);
+                }
+            }
+
+            // special magic for the getdown.txt config: if the parsed data contains 'strict_comments =
+            // true' then we reparse the file with strict comments (i.e. # is only assumed to start a
+            // comment in column 0)
+            if (!opts.strictComments && Boolean.parseBoolean((String)data.get("strict_comments"))) {
+                opts.strictComments = true;
+                return parseConfig(source, opts);
             }
-        }
 
-        // special magic for the getdown.txt config: if the parsed data contains 'strict_comments =
-        // true' then we reparse the file with strict comments (i.e. # is only assumed to start a
-        // comment in column 0)
-        if (!opts.strictComments && Boolean.parseBoolean((String)data.get("strict_comments"))) {
-            opts.strictComments = true;
-            return parseConfig(source, opts);
+            return new Config(data);
         }
 
-        return new Config(data);
-    }
+    public static Config parseConfig (Reader source, ParseOpts opts)
+            throws IOException
+        {
+            Map<String, Object> data = new HashMap<>();
+
+            // I thought that we could use HashMap<String, String[]> and put new String[] {pair[1]} for
+            // the null case, but it mysteriously dies on launch, so leaving it as HashMap<String,
+            // Object> for now
+            for (String[] pair : parsePairs(source, opts)) {
+                Object value = data.get(pair[0]);
+                if (value == null) {
+                    data.put(pair[0], pair[1]);
+                } else if (value instanceof String) {
+                    data.put(pair[0], new String[] { (String)value, pair[1] });
+                } else if (value instanceof String[]) {
+                    String[] values = (String[])value;
+                    String[] nvalues = new String[values.length+1];
+                    System.arraycopy(values, 0, nvalues, 0, values.length);
+                    nvalues[values.length] = pair[1];
+                    data.put(pair[0], nvalues);
+                }
+            }
+
+            // special magic for the getdown.txt config: if the parsed data contains 'strict_comments =
+            // true' then we reparse the file with strict comments (i.e. # is only assumed to start a
+            // comment in column 0)
+            if (!opts.strictComments && Boolean.parseBoolean((String)data.get("strict_comments"))) {
+                opts.strictComments = true;
+                source.reset();
+                return parseConfig(source, opts);
+            }
+
+            return new Config(data);
+        }
 
     public Config (Map<String,  Object> data) {
         _data = data;