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:br.org.acessobrasil.silvinha.util.PropertyLoader.java

/**
 * Salva as propriedades de uma classe/*from w ww.ja  va2  s.c  om*/
 * @param nome nome da classe
 * @param p
 * @throws FileNotFoundException
 * @throws IOException
 */
public static void saveProperty(String nome, Properties p) throws FileNotFoundException, IOException {
    String comments = "# Arquivo de Configurao do Avaliador Silvinha" + "# Criao: 29/11/05 - 17:20"
            + "# Autor: Danniel Nascimento";
    String fileName = nome.toLowerCase();
    File arquivoPropriedades = new File(configPath, fileName + ".properties");
    OutputStream out = new FileOutputStream(arquivoPropriedades);
    p.store(out, comments);
}

From source file:net.firejack.platform.core.utils.MiscUtils.java

/**
 * @param properties//from   w  ww.j  a  v a 2s. c  o m
 * @param append
 * @throws java.io.IOException
 */
public static void setProperties(File properties, Map<String, String> append) throws IOException {
    Properties props = new Properties();
    if (properties.exists()) {
        FileReader reader = new FileReader(properties);
        props.load(reader);
        reader.close();
    } else {
        FileUtils.forceMkdir(properties.getParentFile());
    }

    if (properties.exists() || properties.createNewFile()) {
        props.putAll(append);
        FileWriter writer = new FileWriter(properties);
        props.store(writer, null);
        writer.flush();
        writer.close();
    }
}

From source file:com.tesora.dve.common.PEFileUtils.java

/**
 * Save the specified properties back to a file
 * /* w  w  w  .  ja v a2 s.co m*/
 * @param testClass
 * @param fileName
 * @param props
 * @throws PEException
 */
public static void savePropertiesToClasspath(Class<?> testClass, String fileName, Properties props)
        throws PEException {
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(new File(testClass.getClassLoader().getResource(fileName).toURI()));

        // We will encrypt on a cloned copy of the properties so that we can
        // continue using the properties we have
        Properties clonedProps = (Properties) props.clone();

        encrypt(clonedProps);

        clonedProps.store(fos, "This file was last updated by DVE on:");
    } catch (Exception e) {
        throw new PEException("Error saving properties file '" + fileName + "'", e);
    } finally {
        if (fos != null) {
            try {

                fos.close();
            } catch (Exception e) {
                // ignore
            }
        }
    }
}

From source file:com.hypersocket.i18n.I18N.java

public static void flushOverrides() {

    for (File f : overideProperties.keySet()) {
        try {//from w  ww  . j  a v a  2s.  c  om
            Properties properties = overideProperties.get(f);
            f.getParentFile().mkdirs();
            f.createNewFile();
            FileOutputStream out = new FileOutputStream(f);
            try {
                properties.store(out, "Hypersocket message bundle override file");
            } finally {
                FileUtils.closeQuietly(out);
            }
        } catch (IOException e) {
            log.error("Failed to flush override file " + f.getName(), e);
        }
    }
}

From source file:br.org.acessobrasil.silvinha.util.PropertyLoader.java

public static void saveProperty(Object o, Properties p) throws FileNotFoundException, IOException {
    String comments = "# Arquivo de Configurao do Avaliador Silvinha" + "# Criao: 29/11/05 - 17:20"
            + "# Autor: Danniel Nascimento";
    String fileName = o.getClass().getSimpleName().toLowerCase();
    File arquivoPropriedades = new File(configPath, fileName + ".properties");
    OutputStream out = new FileOutputStream(arquivoPropriedades);
    p.store(out, comments);
}

From source file:com.anjlab.sat3.Program.java

private static void writeUnsatToFile(String resultsFile, Properties statistics) throws IOException {
    OutputStream out = null;/*from  w w w .j a  v  a2 s  . c  om*/
    try {
        out = new FileOutputStream(new File(resultsFile));

        statistics.store(out, "Unsatisfiable");
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:net.firejack.platform.web.security.x509.KeyUtils.java

public static void setProperties(File properties, File keystore, Map<String, String> append)
        throws IOException {
    Properties props = getProperties(properties, keystore);

    if (properties.exists() || properties.createNewFile()) {
        props.putAll(append);/*from  w w  w .j  a va  2  s . c o m*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        props.store(baos, null);

        InputStream stream = new ByteArrayInputStream(baos.toByteArray());
        if (keystore.exists()) {
            KeyPair keyPair = load(keystore);
            if (keyPair != null) {
                try {
                    byte[] decrypt = encrypt(keyPair.getPublic(), baos.toByteArray());
                    stream = new ByteArrayInputStream(decrypt);
                } catch (Exception e) {
                    logger.trace(e);
                }
            }
        }

        FileOutputStream writer = new FileOutputStream(properties);
        IOUtils.copy(stream, writer);
        IOUtils.closeQuietly(writer);
    }
}

From source file:main.java.com.aosa.util.AOSAReadProperties.java

/**
 * Description<code>Properties</code>      <br>
 * By mutou at 2012-1-12 ?05:58:16   <br>
 * boolean      <br>//  ww w .  j  av  a 2 s.  c o  m
 * @param profileName
 *       Properties ??ClassPath
 * @param key
 *       ?? 
 * @param value
 *       ? value
 * @return
 * @throws
 */
public static boolean WriteValue(String profileName, String key, String value) {
    boolean isWrite = false;
    Properties properties = new Properties();
    InputStream input = AOSAReadProperties.class.getClassLoader().getResourceAsStream(profileName);
    try {
        properties.load(input);
        properties.setProperty(key, value);
        URL prourl = AOSAReadProperties.class.getClassLoader().getResource(profileName);
        String filepath = prourl.getFile();
        FileOutputStream fileOutputStream = new FileOutputStream(filepath);
        properties.store(fileOutputStream, "Custum shutDownTime config : conf.properties");
        fileOutputStream.flush();
        fileOutputStream.close();
        isWrite = true;
    } catch (FileNotFoundException e) {
        logger.debug("Properties");
        throw new AOSARuntimeException("Properties", e);
    } catch (IOException e) {
        logger.debug("PropertiesIO");
        throw new AOSARuntimeException("PropertiesIO", e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                logger.debug("IO?");
                throw new AOSARuntimeException("IO?", e);
            }
        }
    }
    return isWrite;
}

From source file:dk.hippogrif.prettyxml.PrettyPrint.java

/**
 * Store properties in file with version in header.
 *
 * @param file to store the properties in
 * @param prop the properties to store//from   ww w.j  ava  2 s .co  m
 * @throws IOException on io error
 */
public static void storeProperties(File file, Properties prop) throws IOException {
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(file);
        prop.store(fos, "prettyxml " + version);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:it.serverSystem.ClusterTest.java

private static void updateSonarPropertiesFile(Orchestrator orchestrator, Map<String, String> props)
        throws IOException {
    Properties propsFile = new Properties();
    try (FileInputStream conf = FileUtils
            .openInputStream(new File(orchestrator.getServer().getHome(), CONF_FILE_PATH))) {
        propsFile.load(conf);/*from   www . j a  v a2s.  c om*/
        propsFile.putAll(props);
    }
    try (FileOutputStream conf = FileUtils
            .openOutputStream(new File(orchestrator.getServer().getHome(), CONF_FILE_PATH))) {
        propsFile.store(conf, "");
    }
}