Example usage for java.util Properties store

List of usage examples for java.util Properties store

Introduction

In this page you can find the example usage for java.util Properties store.

Prototype

public void store(OutputStream out, String comments) throws IOException 

Source Link

Document

Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the #load(InputStream) load(InputStream) method.

Usage

From source file:com.jdom.util.properties.PropertiesUtil.java

public static void writePropertiesFile(Properties properties, File outputFile) throws IllegalArgumentException {
    OutputStream os = null;//from w w  w .  j  a  va2  s  .co m

    try {
        outputFile.delete();
        outputFile.getParentFile().mkdirs();
        outputFile.createNewFile();
        os = new FileOutputStream(outputFile);

        properties.store(os, "");
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.adaptris.core.services.metadata.SimpleSequenceNumberService.java

private static void store(Properties p, File myFile) throws IOException {
    try (OutputStream out = new FileOutputStream(myFile)) {
        p.store(out, "");
    }/*from  w  ww . ja va 2 s . c o m*/
}

From source file:net.zcarioca.zcommons.config.SpringEndToEndTest.java

@BeforeClass
public static void setupFilesystem() {
    setupMockEnvironment();//from www  .j a v a 2  s.c o  m
    createConfDir();
    Properties props = new Properties();
    props.put("value.1", "This is the first value");
    props.put("value.2", "This is the second value");

    try {
        OutputStream out = new FileOutputStream(new File(getConfDir(), "test.properties"));

        props.store(out, "this is a comment");
    } catch (IOException exc) {
        // do nothing
    }
}

From source file:org.apache.solr.client.solrj.SolrSchemalessExampleTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    File tempSolrHome = createTempDir().toFile();
    // Schemaless renames schema.xml -> schema.xml.bak, and creates + modifies conf/managed-schema,
    // which violates the test security manager's rules, which disallow writes outside the build dir,
    // so we copy the example/example-schemaless/solr/ directory to a new temp dir where writes are allowed.
    FileUtils.copyFileToDirectory(new File(ExternalPaths.SERVER_HOME, "solr.xml"), tempSolrHome);
    File collection1Dir = new File(tempSolrHome, "collection1");
    FileUtils.forceMkdir(collection1Dir);
    FileUtils.copyDirectoryToDirectory(new File(ExternalPaths.SCHEMALESS_CONFIGSET), collection1Dir);
    Properties props = new Properties();
    props.setProperty("name", "collection1");
    OutputStreamWriter writer = null;
    try {/*w  ww . j  a  va2  s .  c  o  m*/
        writer = new OutputStreamWriter(FileUtils.openOutputStream(new File(collection1Dir, "core.properties")),
                "UTF-8");
        props.store(writer, null);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception ignore) {
            }
        }
    }
    createJetty(tempSolrHome.getAbsolutePath());
}

From source file:com.github.tddts.jet.util.Util.java

/**
 * Save given property to given propeorty file.
 *
 * @param fileName property file path/*  w  w w.jav  a 2 s.c  o m*/
 * @param key      property key
 * @param value    property value
 */
public static void saveProperty(String fileName, String key, String value) {
    try {
        File file = new File(fileName);
        if (!file.exists())
            file.createNewFile();
        Properties properties = new Properties();

        try (InputStream in = FileUtils.openInputStream(file)) {
            properties.load(in);
        }

        properties.setProperty(key, value);

        try (OutputStream out = FileUtils.openOutputStream(file)) {
            properties.store(out, "");
        }

    } catch (IOException e) {
        throw new ApplicationException(e);
    }
}

From source file:com.rpgsheet.xcom.PimpMyXcom.java

public static void saveApplicationProperties(Properties appProperties) throws IOException {
    String homePath = System.getProperty(SYSTEM_PROPERTY_USER_HOME);
    File appPropertiesFile = new File(homePath, APPLICATION_PROPERTIES_FILE);
    FileWriter fileWriter = new FileWriter(appPropertiesFile);
    appProperties.store(fileWriter, APPLICATION_COMMENT);
    fileWriter.close();//from  ww  w.ja v a 2s.  c  o  m
}

From source file:net.padlocksoftware.padlock.KeyManager.java

/**
 * Export the supplied Keypair to an output Stream.
 *
 * @param pair The KeyPair to export.  KeyPairs should only be pairs
 * created with the createKeyPair(int) method.
 *
 * @param stream The stream to write the KeyPair to.  Key streams contain both the
 * public and private keys and should be secured.
 *
 * @throws java.io.IOException For any Stream IO related exceptions
 * @throws java.lang.NullPointerException If either parameter is null
 * @since 2.0//  ww  w . j a  v  a  2 s . co m
 */
public static void exportKeyPair(KeyPair pair, OutputStream stream) throws IOException {
    if (pair == null) {
        throw new IllegalArgumentException("KeyPair may not be null");
    }

    if (stream == null) {
        throw new IllegalArgumentException("Stream may not be null");
    }

    //
    // Turn the keypair into properties
    //
    Properties p = new Properties();

    String pri = new String(Hex.encodeHex(pair.getPrivate().getEncoded()));
    String pub = new String(Hex.encodeHex((pair.getPublic().getEncoded())));
    p.setProperty("public", pub);
    p.setProperty("private", pri);

    p.store(stream, null);
    stream.flush();
    stream.close();

}

From source file:com.kixeye.chassis.bootstrap.TestUtils.java

@SuppressWarnings("unchecked")
public static void writePropertiesToFile(String path, Set<Path> filesCreated,
        SimpleEntry<String, String>... entries) {
    Properties properties = new Properties();
    for (SimpleEntry<String, String> entry : entries) {
        properties.put(entry.getKey(), entry.getValue());
    }/*from www.j  a  v  a2 s.  c o  m*/
    Path p = Paths.get(SystemPropertyUtils.resolvePlaceholders(path));
    try (OutputStream os = createFile(p.toString())) {
        properties.store(os, "test properties");
        filesCreated.add(p);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.powers.wsexplorer.gui.GUIUtil.java

public static void saveProperties(Properties p, String file) {
    FileOutputStream fos = null;/*from  w ww .j a v a  2s.  c  o  m*/
    try {
        fos = new FileOutputStream(new File(file));
        p.store(fos, "User saved");
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (fos != null) {
        try {
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
            // ignore
        }
    }
}

From source file:de.uniluebeck.itm.spyglass.SpyglassEnvironment.java

private static void storeProps(final Properties props) throws IOException {

    final OutputStream output = new FileOutputStream(PROPERTY_FILE);
    props.store(output, "this property file contains some basic parameters for Spyglass");
}