Java Code Examples for java.util.Properties#save()

The following examples show how to use java.util.Properties#save() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Alias.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void save(OutputStream out) {
    try {
        Properties props = new Properties();
        for (Enumeration<String> e = keys(); e.hasMoreElements();) {
            String k = e.nextElement();
            String[] a = (String[]) get(k);

            StringBuffer sb = new StringBuffer();

            for (int i = 0; i < a.length; i++) {
                sb.append(a[i].trim());
                if (i < a.length - 1) {
                    sb.append(" ");
                }
            }
            props.put(k.trim(), sb.toString());
        }
        props.save(out, "aliases");
    } finally {
        try {
            out.close();
        } catch (Exception ignored) {
        }
    }
}
 
Example 2
Source File: ObjectContextTest.java    From oodt with Apache License 2.0 6 votes vote down vote up
public void setUp() throws Exception {
	super.setUp();

	aliasFile = File.createTempFile("test", ".properties");
	aliasFile.deleteOnExit();
	Properties aliases = new Properties();
	aliases.setProperty("urn:alias:x", "urn:a:x");
	FileOutputStream out = new FileOutputStream(aliasFile);
	aliases.save(out, "Temporary properties");
	out.close();

	a1 = new TContext("urn:a");
	a2 = new TContext("urn:a");
	b = new TContext("urn:b");

	oldValue = System.getProperty("org.apache.oodt.commons.object.jndi.aliases");
	System.setProperty("org.apache.oodt.commons.object.jndi.aliases", aliasFile.toString());

	List contexts = new ArrayList();
	contexts.add(a1);
	contexts.add(a2);
	contexts.add(b);
	context = new ObjectContext(contexts);
}