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.relativitas.maven.plugins.formatter.FormatterMojo.java

private void storeFileHashCache(ResultCollector rc, Properties props) {
    if (rc.hashUpdatedCount > 0) {
        File cacheFile = new File(targetDirectory, CACHE_PROPERTIES_FILENAME);
        OutputStream out = null;/*from w ww .j a v a  2  s  .  c  o m*/
        try {
            out = buildContext.newFileOutputStream(cacheFile);
            props.store(out, null);
            buildContext.setValue(CACHE_PROPERTIES_FILENAME, props);
        } catch (IOException e) {
            getLog().warn("Cannot store file hash cache properties file", e);
            return;
        } finally {
            IOUtil.close(out);
        }
    }
}

From source file:com.jaxio.celerio.Brand.java

public Brand() {
    brandingPath = System.getProperty("user.home") + "/.celerio/branding.properties";
    logoPath = System.getProperty("user.home") + "/.celerio/" + logoFilename;
    try {//  www  .j a v  a 2  s .c  om

        Properties p = new Properties();
        File f = new File(brandingPath);
        if (f.exists()) {
            p.load(new FileInputStream(f));
            companyName = p.getProperty("company_name", companyName);
            companyUrl = p.getProperty("company_url", companyUrl);
            footer = p.getProperty("footer", footer);
            rootPackage = p.getProperty("root_package", rootPackage);
        } else {
            p.setProperty("root_package", rootPackage);
            p.setProperty("company_name", companyName);
            p.setProperty("company_url", companyUrl);
            p.setProperty("footer", footer);
            if (!f.getParentFile().exists()) {
                f.getParentFile().mkdirs();
            }
            p.store(new FileOutputStream(f), "CELERIO BRANDING");
        }

        // copy logo if not present
        File logo = new File(logoPath);
        if (!logo.exists()) {
            PathMatchingResourcePatternResolver o = new PathMatchingResourcePatternResolver();
            Resource defaultBrandLogo = o.getResource("classpath:/brand-logo.png");
            new FileOutputStream(logo).write(IOUtils.toByteArray(defaultBrandLogo.getInputStream()));
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.cubeia.maven.plugin.firebase.FirebaseRunPlugin.java

private void modifyServerConfiguration(FirebaseDirectory dir) throws MojoExecutionException {
    if (serverBindAddress != null) {
        File conf = new File(dir.confDirectory, "server.props");
        try {/* ww  w.  j av  a 2  s  .co m*/
            InputStream in = new FileInputStream(conf);
            Properties p = new Properties();
            p.load(in);
            p.setProperty(BIND_ADDRESS_PROP, serverBindAddress);
            in.close();
            OutputStream out = new FileOutputStream(conf);
            p.store(out, "Properties modified by firebase:run plugin");
            out.close();
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to modify server configuration", e);
        }
    }
}

From source file:com.manydesigns.elements.blobs.Blob.java

public void saveMetaProperties() throws IOException {
    Properties metaProperties = new Properties();
    createTimestamp = new DateTime();

    safeSetProperty(metaProperties, CODE_PROPERTY, code);
    safeSetProperty(metaProperties, FILENAME_PROPERTY, filename);
    safeSetProperty(metaProperties, CONTENT_TYPE_PROPERTY, contentType);
    safeSetProperty(metaProperties, SIZE_PROPERTY, Long.toString(size));
    safeSetProperty(metaProperties, CREATE_TIMESTAMP_PROPERTY, formatter.print(createTimestamp));
    safeSetProperty(metaProperties, CHARACTER_ENCODING_PROPERTY, characterEncoding);

    OutputStream metaStream = null;
    try {//www .j  ava2  s  .  c  om
        metaStream = new FileOutputStream(metaFile);
        metaProperties.store(metaStream, COMMENT);
    } finally {
        IOUtils.closeQuietly(metaStream);
    }
}

From source file:com.cubeia.maven.plugin.firebase.FirebaseRunPlugin.java

private void modifyClusterConfiguration(FirebaseDirectory dir) throws MojoExecutionException {
    File conf = new File(dir.confDirectory, "cluster.props");
    try {/*w  ww  . ja  v  a 2s  .c  o m*/
        InputStream in = new FileInputStream(conf);
        Properties p = new Properties();
        p.load(in);
        p.setProperty(WEB_DIR_PROP, new File(dir.gameDirectory, "web").getAbsolutePath());
        in.close();
        OutputStream out = new FileOutputStream(conf);
        p.store(out, "Properties modified by firebase:run plugin");
        out.close();
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to modify server configuration", e);
    }
}

From source file:com.liferay.ide.sdk.core.SDK.java

protected void persistAppServerProperties(Map<String, String> properties)
        throws FileNotFoundException, IOException, ConfigurationException {
    IPath loc = getLocation();//w  w  w. ja  v  a 2  s  . c om

    // check for build.<username>.properties

    String userName = System.getProperty("user.name"); //$NON-NLS-1$

    File userBuildFile = loc.append("build." + userName + ".properties").toFile(); //$NON-NLS-1$ //$NON-NLS-2$

    if (userBuildFile.exists()) {
        /*
         * the build file exists so we need to check the following conditions 1. if the header in the comment
         * contains the text written by a previous SDK operation then we can write it again 2. if the file was not
         * previously written by us we will need to prompt the user with permission yes/no to update the
         * build.<username>.properties file
         */

        PropertiesConfiguration propsConfig = new PropertiesConfiguration(userBuildFile);

        String header = propsConfig.getHeader();

        boolean shouldUpdateBuildFile = false;

        if (header != null && header.contains(MSG_MANAGED_BY_LIFERAY_IDE)) {
            shouldUpdateBuildFile = true;
        } else {
            String overwrite = getPrefStore().get(SDKCorePlugin.PREF_KEY_OVERWRITE_USER_BUILD_FILE, ALWAYS);

            if (ALWAYS.equals(overwrite)) {
                shouldUpdateBuildFile = true;
            } else {
                shouldUpdateBuildFile = false;
            }
        }

        if (shouldUpdateBuildFile) {
            for (String key : properties.keySet()) {
                propsConfig.setProperty(key, properties.get(key));
            }

            propsConfig.setHeader(MSG_MANAGED_BY_LIFERAY_IDE);
            propsConfig.save(userBuildFile);
        }

    } else {
        Properties props = new Properties();

        props.putAll(properties);

        props.store(new FileOutputStream(userBuildFile), MSG_MANAGED_BY_LIFERAY_IDE);
    }

}

From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java

@Test
public void testNewBlackDuckPassword() throws Exception {
    final File configFile = File.createTempFile("soleng_framework_core_config_ConfigurationFileTest",
            "testConfigFileRoundTrip");
    filesToDelete.add(configFile);//ww  w .ja v  a  2s  .  com
    configFile.deleteOnExit();

    final Properties props = new Properties();
    final String psw = "blackduck";
    System.out.println("psw: " + psw);
    props.setProperty("protex.server.name", "servername");
    props.setProperty("protex.user.name", "username");
    props.setProperty("protex.password", psw);

    // Write the config file with plain txt password
    configFile.delete();
    props.store(new FileOutputStream(configFile), "test");

    // First use will encrypt password
    ConfigurationManager config = new TestProtexConfigurationManager(configFile.getAbsolutePath());
    assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword());

    // Second use will read encrypted password
    config = new TestProtexConfigurationManager(configFile.getAbsolutePath());
    assertEquals(psw, config.getServerBean(APPLICATION.PROTEX).getPassword());
}

From source file:com.wandisco.s3hdfs.rewrite.redirect.MultiPartFileRedirect.java

/**
 * Sends a PUT command to create the container directory inside of HDFS.
 * It uses the URL from the original request to do so.
 *
 * @throws IOException//from  w  w  w  .j a  v  a2  s .c o m
 * @throws ServletException
 */
public void sendInitiate() throws IOException, ServletException {
    PutMethod httpPut = (PutMethod) getHttpMethod(request.getScheme(), request.getServerName(),
            request.getServerPort(), "MKDIRS", path.getUserName(), path.getHdfsRootUploadPath(), PUT);

    //Make /root/user/bucket/object/version/upload directory
    httpClient.executeMethod(httpPut);
    httpPut.releaseConnection();
    assert httpPut.getStatusCode() == 200;

    response.setHeader("Set-Cookie", httpPut.getResponseHeader("Set-Cookie").getValue());

    // Make /root/user/bucket/object/version/.meta file
    // Set up HttpPut
    httpPut = (PutMethod) getHttpMethod(request.getScheme(), request.getServerName(), request.getServerPort(),
            "CREATE&overwrite=true", path.getUserName(), path.getFullHdfsMetaPath(), PUT);

    // Set custom metadata headers
    Enumeration headers = request.getHeaderNames();
    Properties metadata = new Properties();
    while (headers.hasMoreElements()) {
        String key = (String) headers.nextElement();
        if (key.startsWith("x-amz-meta-")) {
            metadata.setProperty(key, request.getHeader(key));
        }
    }

    // Include lastModified header
    SimpleDateFormat rc228 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    String modTime = rc228.format(Calendar.getInstance().getTime());
    metadata.setProperty("Last-Modified", modTime);

    // Store metadata headers into serialized HashMap in HttpPut entity.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    metadata.store(baos, null);

    httpPut.setRequestEntity(new ByteArrayRequestEntity(baos.toByteArray()));
    httpPut.setRequestHeader(S3_HEADER_NAME, S3_HEADER_VALUE);
    httpClient.executeMethod(httpPut);

    LOG.debug("1st response: " + httpPut.getStatusLine().toString());

    boolean containsRedirect = (httpPut.getResponseHeader("Location") != null);
    LOG.debug("Contains redirect? " + containsRedirect);

    if (!containsRedirect) {
        LOG.error("1st response did not contain redirect. " + "No metadata will be created.");
        return;
    }

    // Handle redirect header transition
    assert httpPut.getStatusCode() == 307;
    Header locationHeader = httpPut.getResponseHeader("Location");
    httpPut.setURI(new URI(locationHeader.getValue(), true));

    // Consume response and re-allocate connection for redirect
    httpPut.releaseConnection();
    httpClient.executeMethod(httpPut);

    LOG.debug("2nd response: " + httpPut.getStatusLine().toString());

    if (httpPut.getStatusCode() != 200) {
        LOG.debug("Response content: " + httpPut.getResponseBodyAsString());
    }

    // Consume 2nd response, assure it was a 200
    httpPut.releaseConnection();
    assert httpPut.getStatusCode() == 200;
}

From source file:com.ecyrd.jspwiki.providers.WikiVersioningFileProvider.java

/**
 * Writes the page properties back to the file system. Note that it WILL overwrite any previous
 * properties.//w  w  w  .  j av a 2  s  .  com
 */
private void putPageProperties(String page, Properties properties) throws IOException {
    File propertyFile = new File(findOldPageDir(page), PROPERTYFILE);
    OutputStream out = null;

    try {
        out = new FileOutputStream(propertyFile);

        properties.store(out, " JSPWiki page properties for " + page + ". DO NOT MODIFY!");
    } finally {
        if (out != null) {
            out.close();
        }
    }
}