Search in sources :

Example 31 with OrderedProperties

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(""));
}
Also used : OrderedProperties(net.i2p.util.OrderedProperties) StructureTest(net.i2p.data.StructureTest) Test(org.junit.Test)

Example 32 with OrderedProperties

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;
}
Also used : OrderedProperties(net.i2p.util.OrderedProperties)

Example 33 with OrderedProperties

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;
}
Also used : OrderedProperties(net.i2p.util.OrderedProperties) IOException(java.io.IOException) OrderedProperties(net.i2p.util.OrderedProperties) Properties(java.util.Properties) File(java.io.File)

Example 34 with OrderedProperties

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) {
            }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OrderedProperties(net.i2p.util.OrderedProperties) IOException(java.io.IOException) Resources(android.content.res.Resources) Properties(java.util.Properties) OrderedProperties(net.i2p.util.OrderedProperties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

OrderedProperties (net.i2p.util.OrderedProperties)34 Properties (java.util.Properties)20 IOException (java.io.IOException)16 File (java.io.File)12 Map (java.util.Map)8 RouterAddress (net.i2p.data.router.RouterAddress)6 UnknownHostException (java.net.UnknownHostException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 InetAddress (java.net.InetAddress)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 StructureTest (net.i2p.data.StructureTest)3 Test (org.junit.Test)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2 Socket (java.net.Socket)2 GeneralSecurityException (java.security.GeneralSecurityException)2 I2PSessionException (net.i2p.client.I2PSessionException)2