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.qpark.maven.plugin.springconfig.ApplicationPropertiesConfigXmlGenerator.java

public void generate() {
    this.log.debug("+generate");
    StringBuffer sb = new StringBuffer(1024);
    sb.append(this.getXmlDefinition());
    sb.append(Util.getGeneratedAtXmlComment(this.getClass(), this.eipVersion));

    sb.append("\n");
    sb.append(this.getPropertiesDefinition());
    sb.append("\n");
    sb.append("</beans>\n");

    File f = Util.getFile(this.outputDirectory,
            new StringBuffer(32).append(this.basePackageName).append(".properties-config.xml").toString());
    this.log.info(new StringBuffer().append("Write ").append(f.getAbsolutePath()));

    try {/*ww  w .j av  a 2 s  .  c o  m*/
        Util.writeToFile(f, sb.toString());
    } catch (Exception e) {
        this.log.error(e.getMessage());
        e.printStackTrace();
    }

    Properties p = this.getGeneratedProperties();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    f = Util.getFile(this.outputDirectory, "eip.generated.properties");
    try {
        String prefix = Util.capitalizePackageName(this.basePackageName);
        p.store(baos, "Build time generated properties");
        sb.setLength(0);
        sb.append(new String(baos.toByteArray()));
        sb.append("\n# Some additional properties that might to be set\n");
        sb.append("# Properties of the ").append(prefix).append("DataSourceJdbc default object:\n");
        sb.append("#").append(prefix).append(".jdbc.driverClassName=\n");
        sb.append("#").append(prefix).append(".jdbc.url=\n");
        sb.append("#").append(prefix).append(".jdbc.username=\n");
        sb.append("#").append(prefix).append(".jdbc.password=\n");
        sb.append("# Properties of the SelfCallingIntegrationConfig.xml\n");
        sb.append("#eip.internal.self.calling.username=\n");
        sb.append("#eip.internal.self.calling.password=\n");
        sb.append("#eip.internal.self.calling.xxx.endpoint=\n");
        sb.append("#").append(prefix).append("=\n");
        // sb.append("#").append(prefix).append("=\n");

        Util.writeToFile(f, sb.toString());
    } catch (Exception e) {
        this.log.error(e.getMessage());
        e.printStackTrace();
    }

    this.log.debug("-generate");
}

From source file:com.u2apple.tool.dao.DeviceI18nDaoImpl.java

private void storeProperties(Properties properties, String fileKey) throws FileNotFoundException, IOException {
    Properties tempProperties = new Properties() {
        @Override//from ww  w. j  av a2s. c  o  m
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }
    };
    tempProperties.putAll(properties);
    String file = Configuration.getProperty(fileKey);
    tempProperties.store(new FileOutputStream(file), null);
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ResultFileWriter.java

/**
 * Prints the properties to the result file.  This uses a roundabout way to
 * store properties, but using Java's underlying encoding mechanism ensures
 * Unicode and special characters are escaped correctly.
 * //  w w  w. j  av a 2  s  . co m
 * @param properties the properties
 * @throws IOException if an I/O error occurred
 */
private void printProperties(Properties properties) throws IOException {
    StringWriter stringBuffer = new StringWriter();
    BufferedReader reader = null;

    properties.store(stringBuffer, null);

    try {
        reader = new BufferedReader(new StringReader(stringBuffer.toString()));

        reader.readLine(); //skip first line that contains the timestamp

        String line = null;
        while ((line = reader.readLine()) != null) {
            writer.print("//");
            writer.println(line);
        }
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}

From source file:com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImplTest.java

@Test
void shouldReturnAgentAutoRegisterPropertiesIfPresent() throws Exception {
    Properties properties = new Properties();

    properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_KEY, "foo");
    properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_RESOURCES, "foo, zoo");
    properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_ENVIRONMENTS, "foo, bar");
    properties.put(AgentAutoRegistrationPropertiesImpl.AGENT_AUTO_REGISTER_HOSTNAME, "agent01.example.com");
    properties.store(new FileOutputStream(configFile), "");

    AgentAutoRegistrationProperties reader = new AgentAutoRegistrationPropertiesImpl(configFile);
    assertThat(reader.agentAutoRegisterKey()).isEqualTo("foo");
    assertThat(reader.agentAutoRegisterResources()).isEqualTo("foo, zoo");
    assertThat(reader.agentAutoRegisterEnvironments()).isEqualTo("foo, bar");
    assertThat(reader.agentAutoRegisterHostname()).isEqualTo("agent01.example.com");
}

From source file:com.asakusafw.testdriver.inprocess.InProcessJobExecutorTest.java

private void putPropertiesFile(Properties props, File file) {
    file.getParentFile().mkdirs();//from  ww w .  ja v a  2s . c o m
    try (OutputStream output = new FileOutputStream(file)) {
        props.store(output, null);
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}

From source file:com.iggroup.oss.restdoclet.doclet.RestDocumentationProperties.java

/**
 * Writes the properties in this object to an output-stream.
 * //w w  w  .java 2 s  . c o  m
 * @param out the output-stream the properties have to be written to.
 * @throws IOException if the output-stream can't be written to.
 */
public void store(final OutputStream out) throws IOException {
    final Properties props = new Properties();
    props.put(ARTIFACT_ID, artifactId);
    props.put(VERSION, version);
    props.put(FINAL_NAME, finalName);
    props.put(CLASSIFIER, classifier);
    props.put(SCM_URL, scmUrl);
    props.put(TIMESTAMP, timestamp);
    props.store(out, "RESTDocumentation properies");
}

From source file:org.gvnix.service.roo.addon.addon.ws.importt.WSImportOperationsImpl.java

/**
 * Store properties into a output stream
 * //w  w w  .j a  va  2 s. c  o m
 * @param serviceClass
 * @param serviceName
 * @param os
 * @param properties
 * @throws IOException
 */
private void storeProperties(JavaType serviceClass, String serviceName, OutputStream os, Properties properties)
        throws IOException {
    properties.store(os, "Service '".concat(serviceName)
            .concat("' security properities. Class ".concat(serviceClass.getFullyQualifiedTypeName())));
}

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

public void testBeanCurrentDir() {
    Properties properties = new Properties();
    properties.setProperty("testbean.current_dir", "current dir");
    File file = new File(System.getProperty("user.dir"), "test-config.properties");
    try {/*from w  w w .ja va2s. c o m*/
        FileOutputStream fos = new FileOutputStream(file);
        properties.store(fos, "");
        fos.close();
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    getBean();
    assertEquals("default", bean.getPropertyDefault());
    assertEquals("classpath", bean.getPropertyClassPath());
    assertEquals("current dir", bean.getPropertyCurrentDir());
    assertEquals("user home dir...sample", bean.getPropertyUserHome());
    file.delete();
}

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

public void testBeanHomeDir() {
    Properties properties = new Properties();
    properties.setProperty("testbean.user_home", "user home dir");
    File file = new File(System.getProperty("user.home"), "test-config.properties");
    try {//from w ww  .j  a v a 2 s  .  c o m
        FileOutputStream fos = new FileOutputStream(file);
        properties.store(fos, "");
        fos.close();
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    getBean();
    assertEquals("default", bean.getPropertyDefault());
    assertEquals("classpath", bean.getPropertyClassPath());
    assertEquals("current dir...sample", bean.getPropertyCurrentDir());
    assertEquals("user home dir", bean.getPropertyUserHome());
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.MergePropertiesMojo.java

private Properties sortProperties(Properties properties) throws ConfigurationException, IOException {
    Properties sp = new SortedProperties();
    sp.putAll(properties);//from   w  w  w.ja  v a 2s  .com

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    sp.store(baos, null);

    properties.clear();
    properties.load(new ByteArrayInputStream(baos.toByteArray()));

    return properties;
}