use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.
the class RouterAddressTest method testNullEquals.
@Test
public void testNullEquals() {
// addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
OrderedProperties options = new OrderedProperties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
RouterAddress addr = new RouterAddress("Blah", options, 42);
assertFalse(addr.equals(null));
assertFalse(addr.equals(""));
}
use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.
the class HostTxtEntry method parseProps.
/**
* @param line part after the #!
* @throws IllegalArgumentException on dup key and other errors
*/
private static OrderedProperties parseProps(String line) throws IllegalArgumentException {
line = line.trim();
OrderedProperties rv = new OrderedProperties();
String[] entries = DataHelper.split(line, "#");
for (int i = 0; i < entries.length; i++) {
String kv = entries[i];
int eq = kv.indexOf('=');
if (eq <= 0 || eq == kv.length() - 1)
throw new IllegalArgumentException("No value: \"" + kv + '"');
String k = kv.substring(0, eq);
String v = kv.substring(eq + 1);
Object old = rv.setProperty(k, v);
if (old != null)
throw new IllegalArgumentException("Dup key: " + k);
}
return rv;
}
use of net.i2p.util.OrderedProperties in project i2p.i2p by i2p.
the class Router method saveConfig.
/**
* Save the current config options (returning true if save was
* successful, false otherwise)
*
* Synchronized with file read in getConfig()
*/
public boolean saveConfig() {
try {
Properties ordered = new OrderedProperties();
synchronized (_configFileLock) {
ordered.putAll(_config);
DataHelper.storeProps(ordered, new File(_configFilename));
}
} catch (IOException ioe) {
// warning, _log will be null when called from constructor
if (_log != null)
_log.error("Error saving the config to " + _configFilename, ioe);
else
System.err.println("Error saving the config to " + _configFilename + ": " + ioe);
return false;
}
return true;
}
use of net.i2p.util.OrderedProperties in project i2p.i2p-bote by i2p.
the class Init method mergeResourceToFile.
/**
* Load defaults from resource,
* then add props from settings,
* and write back
*
* @param f relative to base dir
* @param overrides local overrides or null
*/
public void mergeResourceToFile(int resID, String f, Properties overrides) {
InputStream in = null;
InputStream fin = null;
try {
in = ctx.getResources().openRawResource(resID);
Properties props = new OrderedProperties();
try {
fin = new FileInputStream(new File(myDir, f));
DataHelper.loadProps(props, fin);
} catch (IOException ioe) {
}
// write in default settings
DataHelper.loadProps(props, in);
// override with user settings
if (overrides != null)
props.putAll(overrides);
File path = new File(myDir, f);
DataHelper.storeProps(props, path);
} catch (IOException ioe) {
} catch (Resources.NotFoundException nfe) {
} finally {
if (in != null)
try {
in.close();
} catch (IOException ioe) {
}
if (fin != null)
try {
fin.close();
} catch (IOException ioe) {
}
}
}
Aggregations