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:dkpro.similarity.algorithms.vsm.store.vectorindex.VectorIndexWriter.java

private BerkeleyDbDatabase getDb() throws IOException {
    if (db == null) {
        dbEnv = new BerkeleyDbEnvironment(path.getAbsolutePath(), false, true, dbCacheSize);

        // init conceptVectorIndex
        TupleBinding<?> binding = new VectorBinding(nConcepts);
        db = new BerkeleyDbDatabase(dbEnv, CONCEPT_VECTOR_DB_NAME, false, true, binding);

        Writer out = null;/*from ww w. j av  a2  s .  co  m*/
        try {
            Properties props = new Properties();
            props.setProperty(CONFIG_PROP_N_CONCEPTS, String.valueOf(nConcepts));
            out = new OutputStreamWriter(new FileOutputStream(new File(path, CONFIG_FILE_NAME)),
                    CONFIG_FILE_ENCODING);
            props.store(out, null);
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
    return db;
}

From source file:br.edu.ufcg.lsd.commune.context.PropertiesFileParser.java

private Map<Object, Object> getDefaultProperties(File propertiesFile) {

    Properties properties = new Properties();

    properties.putAll(new DefaultContextFactory().getDefaultProperties());
    try {/*from ww w.  j  ava2s. c  o m*/
        FileUtils.touch(propertiesFile);

        FileOutputStream fileOutputStream = new FileOutputStream(propertiesFile);
        properties.store(fileOutputStream, null);
        fileOutputStream.close();

    } catch (Exception e) {
        e.printStackTrace();
        throw new CommuneRuntimeException("File could not be created: " + fileName);
    }
    return properties;
}

From source file:net.dempsy.distconfig.apahcevfs.ApacheVfsPropertiesStore.java

@Override
public int merge(final Properties props) throws IOException {
    return mapChecked(() -> {
        final FileObject latest = getLatest(parentDirObj);
        if (latest == null)
            return push(props);

        final Properties oldProps = read(latest);
        final Properties newProps = new Properties();
        newProps.putAll(oldProps);/*from   w  w  w.j a  va2s .c om*/
        newProps.putAll(props);

        final FileObject next = nextFile(latest, parentDirObj);
        try (OutputStream os = next.getContent().getOutputStream()) {
            newProps.store(os, COMMENT);
        }
        return new Integer(getVersion(next));
    }, em).intValue();
}

From source file:com.meltmedia.cadmium.core.config.impl.PropertiesWriterImpl.java

@Override
public void persistProperties(Properties properties, File propsFile, String message, Logger log) {

    if (propsFile.canWrite() || !propsFile.exists()) {

        FileOutputStream out = null;

        try {/*from ww  w. j av  a  2  s.co m*/

            ensureDirExists(propsFile.getParent());
            out = new FileOutputStream(propsFile);
            properties.store(out, message);
            out.flush();
        } catch (Exception e) {

            log.warn("Failed to persist vault properties file.", e);
        } finally {
            IOUtils.closeQuietly(out);
        }

    }

}

From source file:net.fatlenny.datacitation.service.GitCitationDBService.java

@Override
public Status saveQuery(Query query) throws CitationDBException {
    checkoutBranch(REF_QUERIES);/*w w w. jav a 2s.c o m*/

    String pidIdentifier = query.getPid().getIdentifier();
    String fileName = DigestUtils.sha1Hex(pidIdentifier) + "." + QUERY_ENDING;
    try (Git git = new Git(repository)) {
        Path filePath = Paths.get(getWorkingTreeDir(), fileName);
        Properties properties = writeQueryToProperties(query);
        properties.store(
                Files.newBufferedWriter(filePath, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW), "");
        git.add().addFilepattern(fileName).call();
        PersonIdent personIdent = new PersonIdent("ReCitable", "recitable@fatlenny.net");
        String message = String.format("Created query file for PID=%s", pidIdentifier);
        git.commit().setMessage(message).setAuthor(personIdent).setCommitter(personIdent).call();
    } catch (IOException | GitAPIException e) {
        throw new CitationDBException(e);
    }

    return Status.SUCCESS;
}

From source file:com.edgenius.core.Server.java

/**
 * Save to data root server.xml/*from w w w .  j a  v  a2s  . c  om*/
 * @throws IOException 
 */
public void saveTo() throws IOException {
    OutputStream os = null;
    try {
        String root = DataRoot.getDataRoot();
        //save server.properties into file
        os = FileUtil.getFileOutputStream(root + Server.FILE);

        Properties prop = new Properties();
        syncTo(prop);
        prop.store(os, "Save from system program");
    } finally {
        try {
            if (os != null)
                os.close();
        } catch (Exception e) {
            // nothing;
        }
    }

}

From source file:ch.uzh.fabric.config.SampleStore.java

/**
 * Set the value associated with name./*from  w  w w .j  a  v a2s  . co m*/
 *
 * @param name The name of the parameter
 * @param value Value for the parameter
 */
public void setValue(String name, String value) {
    Properties properties = loadProperties();
    try (OutputStream output = new FileOutputStream(file)) {
        properties.setProperty(name, value);
        properties.store(output, "");
        output.close();

    } catch (IOException e) {
        LOGGER.warn(String.format("Could not save the keyvalue store, reason:%s", e.getMessage()));
    }
}

From source file:com.google.gwt.benchmark.compileserver.server.manager.CliInteractor.java

public void storeCommitId(String commitId) throws BenchmarkManagerException {

    Properties prop = new Properties();
    prop.setProperty("commitId", commitId);

    FileOutputStream stream = null;
    try {//from   w  w  w .  j  a va2  s.c  o  m
        stream = new FileOutputStream(new File(persistenceDir, "store"));
        prop.store(stream, null);

    } catch (IOException e) {
        logger.log(Level.WARNING, "Can not read commit from store file", e);
        throw new BenchmarkManagerException("Can not read commit from store file", e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
}

From source file:net.dempsy.distconfig.apahcevfs.ApacheVfsPropertiesStore.java

@Override
public int clear(final String... props) throws IOException {
    return mapChecked(() -> {
        final FileObject latest = getLatest(parentDirObj);
        if (latest == null)
            return -1;

        final Properties oldProps = read(latest);
        final Properties newProps = new Properties();
        newProps.putAll(oldProps);/* w  w  w . j  a v a  2  s.  com*/
        Arrays.stream(props).forEach(newProps::remove);

        final FileObject next = nextFile(latest, parentDirObj);
        try (OutputStream os = next.getContent().getOutputStream()) {
            newProps.store(os, COMMENT);
        }
        return new Integer(getVersion(next));
    }, em).intValue();
}

From source file:edu.ku.brc.af.core.db.BackupServiceFactory.java

/**
 * @param stats//from   w w w. j  av  a  2 s .co  m
 * @param fullName
 * @return
 */
protected boolean writeStats(final Properties stats, final String fullName) {
    if (StringUtils.isNotEmpty(fullName)) {
        try {

            stats.store(new FileOutputStream(fullName), "DB TableStatistics"); //$NON-NLS-1$
            return true;

        } catch (IOException ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BackupServiceFactory.class, ex);
            ex.printStackTrace();
            //throw new BackingStoreException(ex);
        }
    }
    return false;
}