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:ases.PropertyLoader.java

/**
 * Salva as propriedades de uma classe//from   w w w. ja  va2 s  .  c o m
 * 
 * @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 Configuração do Avaliador Silvinha"
            + "# Criação: 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:com.moviejukebox.tools.TraktTV.java

private static void storeTraktTvProperties(TokenResponse response) {
    // set properties
    Properties props = new Properties();
    props.setProperty(PROP_ACCESS_TOKEN, response.getAccessToken());
    props.setProperty(PROP_REFRESH_TOKEN, response.getRefreshToken());
    props.setProperty(PROP_EXPIRATION_DATE, String.valueOf(buildExpirationDate(response)));

    // store properties file
    File propsFile = new File(PROPS_FILE);
    try (OutputStream out = new FileOutputStream(propsFile)) {
        props.store(out, "Trakt.TV settings");
    } catch (Exception e) {
        LOG.error("Failed to store Trakt.TV properties");
    }//from  w w w.j  a  va2  s .  c o m
}

From source file:io.fluo.mapreduce.FluoInputFormat.java

/**
 * Configure properties needed to connect to a Fluo instance
 * /*w w w .ja  v  a  2s  . co m*/
 * @param conf
 * @param props
 *          use {@link io.fluo.api.config.FluoConfiguration} to configure programmatically
 */
@SuppressWarnings("deprecation")
public static void configure(Job conf, Properties props) {
    try {
        FluoConfiguration config = new FluoConfiguration(ConfigurationConverter.getConfiguration(props));
        try (Environment env = new Environment(config)) {
            long ts = env.getSharedResources().getTimestampTracker().allocateTimestamp();
            conf.getConfiguration().setLong(TIMESTAMP_CONF_KEY, ts);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            props.store(baos, "");
            conf.getConfiguration().set(PROPS_CONF_KEY, new String(baos.toByteArray(), "UTF8"));

            AccumuloInputFormat.setZooKeeperInstance(conf, config.getAccumuloInstance(),
                    config.getZookeepers());
            AccumuloInputFormat.setConnectorInfo(conf, config.getAccumuloUser(),
                    new PasswordToken(config.getAccumuloPassword()));
            AccumuloInputFormat.setInputTableName(conf, env.getTable());
            AccumuloInputFormat.setScanAuthorizations(conf, env.getAuthorizations());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:net.sourceforge.jaulp.lang.PropertiesUtils.java

/**
 * Converts the given xml InputStream to the given properties OutputStream.
 * //from  w w w  .  ja va2  s .c  o m
 * @param properties
 *            the properties file. The xml file does not have to exist.
 * @param xml
 *            the xml file with the properties to convert.
 * @param comment
 *            the comment
 * @throws FileNotFoundException
 *             the file not found exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void toProperties(OutputStream properties, InputStream xml, String comment)
        throws FileNotFoundException, IOException {
    Properties prop = new Properties();
    prop.loadFromXML(xml);
    prop.store(properties, comment);
}

From source file:com.bluexml.tools.miscellaneous.Translate.java

public static void writeBackValues(File values, File propertiesFile) throws IOException {
    List<String> readLines = FileUtils.readLines(values, "UTF-8");
    Properties props = new Properties();
    TreeMap<String, String> propsMap = loadProperties(propertiesFile);
    Set<String> keySet = propsMap.keySet();
    int index = 0;
    for (String key : keySet) {
        String value = readLines.get(index);
        System.out.println("before trans :" + value);

        System.out.println("after trans :" + value);
        System.out.println();//from   ww  w. j a va 2s  .c o  m
        props.setProperty(key, value);
        index++;
    }

    FileOutputStream out = new FileOutputStream(propertiesFile);
    props.store(out, null);
    out.close();

}

From source file:ases.PropertyLoader.java

public static void saveProperty(Object o, Properties p) throws FileNotFoundException, IOException {

    String comments = "# Arquivo de Configura&ccedil;&atilde;o do Avaliador Silvinha"
            + "# Cria&ccedil;&atilde;o: 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:de.alpharogroup.lang.PropertiesUtils.java

/**
 * Converts the given xml InputStream to the given properties OutputStream.
 * /*from   w ww  .ja va2 s.  c  om*/
 * @param properties
 *            the properties file. The xml file does not have to exist.
 * @param xml
 *            the xml file with the properties to convert.
 * @param comment
 *            the comment
 * @throws FileNotFoundException
 *             the file not found exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void toProperties(final OutputStream properties, final InputStream xml, final String comment)
        throws FileNotFoundException, IOException {
    final Properties prop = new Properties();
    prop.loadFromXML(xml);
    prop.store(properties, comment);
}

From source file:com.bc.fiduceo.TestUtil.java

public static void storeProperties(Properties properties, File configDir, String child) throws IOException {
    final File propertiesFile = new File(configDir, child);
    if (!propertiesFile.createNewFile()) {
        fail("unable to create test file: " + propertiesFile.getAbsolutePath());
    }/*from w  ww  . j a  va  2s  . c om*/

    FileOutputStream outputStream = null;
    try {
        outputStream = new FileOutputStream(propertiesFile);
        properties.store(outputStream, "");
    } finally {
        if (outputStream != null) {
            outputStream.close();
        }
    }
}

From source file:com.streamsets.datacollector.util.ClusterUtil.java

public static void setupCluster(String testName, String pipelineJson, YarnConfiguration yarnConfiguration)
        throws Exception {
    System.setProperty("sdc.testing-mode", "true");
    System.setProperty(MiniSDCTestingUtility.PRESERVE_TEST_DIR, "true");
    yarnConfiguration.set("yarn.nodemanager.delete.debug-delay-sec", "600");
    miniSDCTestingUtility = new MiniSDCTestingUtility();
    File dataTestDir = miniSDCTestingUtility.getDataTestDir();

    //copy spark files under the test data directory into a dir called "spark"
    File sparkHome = ClusterUtil.createSparkHome(dataTestDir);

    //start mini yarn cluster
    miniYarnCluster = miniSDCTestingUtility.startMiniYarnCluster(testName, 1, 1, 1, yarnConfiguration);
    Configuration config = miniYarnCluster.getConfig();

    long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
    while (config.get(YarnConfiguration.RM_ADDRESS).split(":")[1] == "0") {
        if (System.currentTimeMillis() > deadline) {
            throw new IllegalStateException("Timed out waiting for RM to come up.");
        }//w  w  w.  jav  a2s  .com
        LOG.debug("RM address still not set in configuration, waiting...");
        TimeUnit.MILLISECONDS.sleep(100);
    }
    LOG.debug("RM at " + config.get(YarnConfiguration.RM_ADDRESS));

    Properties sparkHadoopProps = new Properties();
    for (Map.Entry<String, String> entry : config) {
        sparkHadoopProps.setProperty("spark.hadoop." + entry.getKey(), entry.getValue());
    }

    LOG.debug("Creating spark properties file at " + dataTestDir);
    File propertiesFile = new File(dataTestDir, "spark.properties");
    propertiesFile.createNewFile();
    FileOutputStream sdcOutStream = new FileOutputStream(propertiesFile);
    sparkHadoopProps.store(sdcOutStream, null);
    sdcOutStream.flush();
    sdcOutStream.close();
    // Need to pass this property file to spark-submit for it pick up yarn confs
    System.setProperty(SPARK_PROPERTY_FILE, propertiesFile.getAbsolutePath());

    File sparkBin = new File(sparkHome, "bin");
    for (File file : sparkBin.listFiles()) {
        MiniSDCTestingUtility.setExecutePermission(file.toPath());
    }

    miniSDC = miniSDCTestingUtility.createMiniSDC(MiniSDC.ExecutionMode.CLUSTER);
    miniSDC.startSDC();
    serverURI = miniSDC.getServerURI();
    miniSDC.createPipeline(pipelineJson);
    miniSDC.startPipeline();

    int attempt = 0;
    //Hard wait for 2 minutes
    while (miniSDC.getListOfSlaveSDCURI().size() == 0 && attempt < 24) {
        Thread.sleep(5000);
        attempt++;
        LOG.debug("Attempt no: " + attempt + " to retrieve list of slaves");
    }
    if (miniSDC.getListOfSlaveSDCURI().size() == 0) {
        throw new IllegalStateException("Timed out waiting for slaves to come up.");
    }
}

From source file:atg.tools.dynunit.util.ComponentUtil.java

private static void writeComponentPropertiesToFile(final File output, final String canonicalClassName,
        final Properties properties) throws IOException {
    logger.entry(output, canonicalClassName, properties);
    BufferedWriter out = null;//from  w  ww. ja  v a  2  s .c  o m
    try {
        out = new BufferedWriter(new FileWriter(output));
        if (StringUtils.isNotEmpty(canonicalClassName)) {
            out.write("$class=");
            out.write(canonicalClassName);
            out.newLine();
        }
        properties.store(out, canonicalClassName);
    } finally {
        if (out != null) {
            out.close();
        }
        logger.exit();
    }
}