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:de.kasoki.jfeedly.model.FeedlyConnection.java

/** Save the connection details to a file */
public void save() {
    Properties prop = new Properties();

    prop.setProperty("access_token", this.accessToken);
    prop.setProperty("refresh_token", this.refreshToken);
    prop.setProperty("plan", this.plan);
    prop.setProperty("token_type", this.tokenType);
    prop.setProperty("id", this.id);
    prop.setProperty("expire_date", Long.toString(this.expireDate.getTime()));

    try {/*  w  w w .j  a v  a2 s . co  m*/
        prop.store(new FileOutputStream(this.connectionFilePath), null);
    } catch (IOException e) {
        System.err.println("This should only appear if you have no rights to write in this folder!");
        e.printStackTrace();
    }
}

From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.SpringBeansUtil.java

private void saveProperties(Properties props) {
    try {/*from  ww w .  ja  v  a2  s.  c  o m*/

        String filePath = SpringBeansUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        File f = new File(filePath);
        if (f.isFile()) {
            filePath = filePath + File.separatorChar + "..";
        }

        File storeFile = new File(filePath + File.separatorChar + STORE_PROPS_FILE);

        props.store(new FileWriter(storeFile), "Generated by Bulk Loader");
    } catch (IOException e) {
        log.error("Error while trying to generate the [" + STORE_PROPS_FILE + "] file", e);
    }
}

From source file:io.syndesis.verifier.LocalProcessVerifier.java

private Properties runValidator(String classpath, Verifier.Scope scope, String camelPrefix, Properties request)
        throws IOException, InterruptedException {
    Process java = new ProcessBuilder().command("java", "-classpath", classpath,
            "io.syndesis.connector.ConnectorVerifier", scope.toString(), camelPrefix)
            .redirectError(ProcessBuilder.Redirect.INHERIT).start();

    try (OutputStream os = java.getOutputStream()) {
        request.store(os, null);
    }/*from  w ww .ja  v  a 2s  .c o  m*/
    Properties result = new Properties();
    try (InputStream is = java.getInputStream()) {
        result.load(is);
    }

    if (java.waitFor() != 0) {
        throw new IOException("Verifier failed with exit code: " + java.exitValue());
    }
    return result;
}

From source file:com.elasticgrid.amazon.boot.Bootstrapper.java

/**
 * Dump Elastic Grid properties into a configuration file.
 *
 * @param egParameters the properties to dump in a file
 * @return the file where the properties have been dumped into.
 * @throws IOException if there is an error when generating the configuration file
 *//*from   ww w . j a v a2  s  .c o  m*/
private File saveConfiguration(Properties egParameters) throws IOException {
    // write EG configuration
    if (egHome == null) {
        System.err.println("Could not find EG_HOME environment variable. Please fix this.");
        System.exit(-1);
    }
    File config = new File(egConfig, ELASTIC_GRID_CONFIGURATION_FILE);
    FileOutputStream stream = null;
    try {
        stream = new FileOutputStream(config);
        egParameters.store(stream, "Elastic Grid Configuration File - Generated file, please do NOT edit!");
    } finally {
        IOUtils.closeQuietly(stream);
    }
    return config;
}

From source file:com.liusoft.dlog4j.plugin.SearchEnginePlugIn.java

/**
 * ?//w  w w. j av  a2  s. c  om
 * 
 * @param pvdClass
 * @param time
 * @throws IOException
 */
private void saveLastActiveTime(String pvdClass, Date time) throws IOException {
    StringBuffer status_file_uri = new StringBuffer(STATUS_FILE_PATH);
    status_file_uri.append(pvdClass);
    status_file_uri.append(".his");
    String realPath = context.getRealPath(status_file_uri.toString());
    Properties props = new Properties();
    FileOutputStream fos = null;
    try {
        props.setProperty(TIME_KEY, String.valueOf(time.getTime()));
        props.setProperty("LAST_TIME", time.toString());
        fos = new FileOutputStream(realPath);
        props.store(fos, null);
    } finally {
        props = null;
        if (fos != null) {
            fos.close();
            fos = null;
        }
    }
}

From source file:com.smartitengineering.util.bean.spring.PropertiesLocatorConfigurerTest.java

public void testAll() {
    Properties properties = new Properties();
    properties.setProperty("testbean.current_dir", "current dir");
    File fileCurrentDir = new File(System.getProperty("user.dir"), "test-config.properties");
    try {/*w w  w .java  2s.com*/
        FileOutputStream fos = new FileOutputStream(fileCurrentDir);
        properties.store(fos, "");
        fos.close();
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    properties = new Properties();
    properties.setProperty("testbean.current_dir", "current dir again");
    properties.setProperty("testbean.user_home", "user home dir");
    File fileUserHome = new File(System.getProperty("user.home"), "test-config.properties");
    try {
        FileOutputStream fos = new FileOutputStream(fileUserHome);
        properties.store(fos, "");
        fos.close();
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    getBean();
    assertEquals("default", bean.getPropertyDefault());
    assertEquals("classpath", bean.getPropertyClassPath());
    assertEquals("current dir again", bean.getPropertyCurrentDir());
    assertEquals("user home dir", bean.getPropertyUserHome());
    fileCurrentDir.delete();
    fileUserHome.delete();
}

From source file:de.codesourcery.jasm16.ide.WorkspaceConfig.java

public void saveConfiguration() throws IOException {

    final Properties props = new Properties();
    for (Map.Entry<String, String> keyValue : configProperties.entrySet()) {
        props.put(keyValue.getKey(), keyValue.getValue());
    }//from  ww w. ja v a  2 s.c  o m

    final String comments = "jASM16 workspace configuration -- automatically generated, do NOT edit";
    try {
        final FileOutputStream out = new FileOutputStream(configFile);
        try {
            props.store(out, comments);
        } finally {
            IOUtils.closeQuietly(out);
        }
    } catch (IOException e) {
        LOG.fatal(
                "createDefaultConfiguration(): Failed to save configuration to " + configFile.getAbsolutePath(),
                e);
        throw e;
    }
}

From source file:annis.security.ANNISUserConfigurationManager.java

private boolean writeGroupFile() {
    if (groupsFile != null) {

        lock.writeLock().lock();/*from ww w .j  a v a2  s.  co  m*/
        try {

            Properties props = new Properties();
            for (Group g : groups.values()) {
                props.put(g.getName(), Joiner.on(',').join(g.getCorpora()));
            }

            try (FileOutputStream outStream = new FileOutputStream(groupsFile)) {
                props.store(outStream, "");
                outStream.close();

                // update the last modification time
                lastTimeReloaded = new Date(groupsFile.lastModified());
                return true;
            } catch (IOException ex) {
                log.error("Could not write groups file", ex);
            }
        } finally {
            lock.writeLock().unlock();
        }
    } // end if resourcePath not null
    return false;
}

From source file:com.redhat.rcm.version.CliTest.java

private void writeConfigTo(final Properties props, final File config) throws IOException {
    FileOutputStream out = null;/*from w ww  .  j av  a2s . c o m*/
    try {
        out = new FileOutputStream(config);
        props.store(out, "Generated for test: " + getClass().getName() + "#" + name.getMethodName());
    } finally {
        closeQuietly(out);
    }
}

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

private void writeProperties(Properties p, File filename, boolean xml) throws Exception {
    OutputStream out = null;// w  w  w.  j  a v a  2  s  . c  o m
    try {
        File parent = filename.getParentFile();
        if (parent != null) {
            parent.mkdirs();
        }
        out = new FileOutputStream(filename);
        if (xml) {
            p.storeToXML(out, "");
        } else {
            p.store(out, "");
        }
    } finally {
        IOUtils.closeQuietly(out);
    }

}