diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index e10f9f8ca..738d84bc0 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -9,10 +9,15 @@ package net.i2p.data; * */ +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.OutputStream; import java.math.BigInteger; import java.util.ArrayList; @@ -129,6 +134,31 @@ public class DataHelper { return buf.toString(); } + /** + * A more efficient Properties.load + * + */ + public static void loadProps(Properties props, File file) throws IOException { + BufferedReader in = null; + try { + in = new BufferedReader(new InputStreamReader(new FileInputStream(file)), 16*1024); + String line = null; + while ( (line = in.readLine()) != null) { + if (line.trim().length() <= 0) continue; + if (line.charAt(0) == '#') continue; + int split = line.indexOf('='); + if (split <= 0) continue; + String key = line.substring(0, split); + String val = line.substring(split+1); + if ( (key.length() > 0) && (val.length() > 0) ) + props.setProperty(key, val); + } + } finally { + if (in != null) try { in.close(); } catch (IOException ioe) {} + } + } + + /** * Pretty print the collection * diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java index bbd5d8265..fea98dc0a 100644 --- a/core/java/src/net/i2p/util/LogManager.java +++ b/core/java/src/net/i2p/util/LogManager.java @@ -59,7 +59,7 @@ public class LogManager { public final static int DEFAULT_CONSOLEBUFFERSIZE = 20; public final static String DEFAULT_ROTATIONLIMIT = "2"; public final static String DEFAULT_DEFAULTLEVEL = Log.STR_ERROR; - public final static String DEFAULT_ONSCREENLEVEL = Log.STR_ERROR; + public final static String DEFAULT_ONSCREENLEVEL = Log.STR_CRIT; private I2PAppContext _context; private Log _log; diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 0f8e3c480..f602d6eb4 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -183,10 +183,9 @@ public class Router { try { File f = new File(filename); if (f.canRead()) { - fis = new FileInputStream(f); - props.load(fis); + DataHelper.loadProps(props, f); } else { - log.error("Configuration file " + filename + " does not exist"); + log.warn("Configuration file " + filename + " does not exist"); } } catch (Exception ioe) { log.error("Error loading the router configuration from " + filename, ioe); diff --git a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java index 26926f47d..b51c4cc98 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java +++ b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java @@ -15,6 +15,7 @@ import java.util.Properties; import java.util.Set; import net.i2p.data.DataFormatException; +import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.router.RouterContext; import net.i2p.util.Log; @@ -212,26 +213,11 @@ class ProfilePersistenceHelper { } private void loadProps(Properties props, File file) { - BufferedReader in = null; try { - in = new BufferedReader(new InputStreamReader(new FileInputStream(file)), 16*1024); - String line = null; - while ( (line = in.readLine()) != null) { - if (line.trim().length() <= 0) continue; - if (line.charAt(0) == '#') continue; - int split = line.indexOf('='); - if (split <= 0) continue; - String key = line.substring(0, split); - String val = line.substring(split+1); - if ( (key.length() > 0) && (val.length() > 0) ) - props.setProperty(key, val); - } + DataHelper.loadProps(props, file); } catch (IOException ioe) { _log.warn("Error loading properties from " + file.getName(), ioe); - } finally { - if (in != null) try { in.close(); } catch (IOException ioe) {} } - } private Hash getHash(String name) { diff --git a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java index 41178ca06..97ab1a86c 100644 --- a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java +++ b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java @@ -1,9 +1,13 @@ package net.i2p.router.startup; import java.lang.reflect.Method; +import java.io.IOException; +import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Properties; +import net.i2p.data.DataHelper; import net.i2p.router.JobImpl; import net.i2p.router.RouterContext; import net.i2p.util.I2PThread; @@ -19,17 +23,22 @@ class LoadClientAppsJob extends JobImpl { private Log _log; /** wait 2 minutes before starting up client apps */ private final static long STARTUP_DELAY = 2*60*1000; + + private static final String PROP_CLIENT_CONFIG_FILENAME = "router.clientConfigFile"; + private static final String DEFAULT_CLIENT_CONFIG_FILENAME = "clients.config"; + public LoadClientAppsJob(RouterContext ctx) { super(ctx); _log = ctx.logManager().getLog(LoadClientAppsJob.class); } public void runJob() { + Properties clientApps = getClientApps(); int i = 0; while (true) { - String className = getContext().router().getConfigSetting("clientApp."+i+".main"); - String clientName = getContext().router().getConfigSetting("clientApp."+i+".name"); - String args = getContext().router().getConfigSetting("clientApp."+i+".args"); - String onBoot = getContext().router().getConfigSetting("clientApp." + i + ".onBoot"); + String className = clientApps.getProperty("clientApp."+i+".main"); + String clientName = clientApps.getProperty("clientApp."+i+".name"); + String args = clientApps.getProperty("clientApp."+i+".args"); + String onBoot = clientApps.getProperty("clientApp." + i + ".onBoot"); boolean onStartup = false; if (onBoot != null) onStartup = "true".equals(onBoot) || "yes".equals(onBoot); @@ -49,6 +58,24 @@ class LoadClientAppsJob extends JobImpl { } } + private Properties getClientApps() { + Properties rv = new Properties(); + String clientConfigFile = getContext().getProperty(PROP_CLIENT_CONFIG_FILENAME, DEFAULT_CLIENT_CONFIG_FILENAME); + File cfgFile = new File(clientConfigFile); + + // fall back to use router.config's clientApp.* lines + if (!cfgFile.exists()) + return new Properties(getContext().router().getConfigMap()); + + try { + DataHelper.loadProps(rv, cfgFile); + } catch (IOException ioe) { + _log.warn("Error loading the client app properties from " + cfgFile.getName(), ioe); + } + + return rv; + } + private class DelayedRunClient extends JobImpl { private String _className; private String _clientName;