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:Main.java

/**
 * Save config file.// ww  w .j  a  va2s  .c o  m
 */
private static void saveConfig(Properties properties) {
    try {
        File file = new File(CONFIG_FILE_PATH);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream s = new FileOutputStream(file);
        properties.store(s, "");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.l2jfree.security.HexID.java

/**
 * Save hexadecimal ID of the server in the properties file.
 * //from   w w  w. j  a  v a2  s.  co m
 * @param serverId game server ID
 * @param hexId (String) : hexadecimal ID of the server to store
 * @param fileName (String) : name of the properties file
 */
public static void saveHexid(int serverId, String hexId, String fileName) {
    OutputStream out = null;
    try {
        out = new FileOutputStream(fileName);

        final Properties hexSetting = new Properties();
        hexSetting.setProperty("ServerID", String.valueOf(serverId));
        hexSetting.setProperty("HexID", hexId);
        hexSetting.store(out, "the hexID to auth into login");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.thoughtworks.go.agent.bootstrapper.osx.AgentMacWindow.java

private static void savePrefs(Properties prefs) {
    FileOutputStream stream = null;
    try {// w w w  .j ava  2  s .c o m
        stream = new FileOutputStream(PREFS_FILE, false);
        prefs.store(stream, null);
    } catch (FileNotFoundException e) {
        LOG.error("File not found for " + PREFS_FILE, e);
    } catch (IOException e) {
        LOG.error("IO exception on " + PREFS_FILE, e);
    } finally {
        closeQuietly(stream);
    }
}

From source file:io.fabric8.profiles.ProfilesHelpers.java

public static byte[] toBytes(Properties properties) throws IOException {
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        properties.store(os, null);
        return os.toByteArray();
    }/*w w  w .ja  v a2s  .  c o  m*/
}

From source file:com.textocat.textokit.commons.io.IoUtils.java

public static void write(Properties props, File outFile) throws IOException {
    BufferedWriter bw = openBufferedWriter(outFile);
    try {//  w w  w .j a va 2 s .co  m
        props.store(bw, null);
    } finally {
        closeQuietly(bw);
    }
}

From source file:com.textocat.textokit.commons.io.IoUtils.java

public static void writeProperties(Properties props, File outFile) throws IOException {
    BufferedWriter ow = openBufferedWriter(outFile);
    try {/*  www .  ja  v  a  2 s  . c  o m*/
        props.store(ow, null);
    } finally {
        closeQuietly(ow);
    }
}

From source file:com.adaptris.core.MimeEncoderImpl.java

protected static byte[] getMetadata(AdaptrisMessage msg) throws IOException {
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        Properties metadata = convertToProperties(msg.getMetadata());
        metadata.store(out, "");
        return out.toByteArray();
    }/*  w ww  .  j  a  v  a 2 s  . c o m*/
}

From source file:com.diffplug.gradle.ConfigMisc.java

/** Creates an XML string from a groovy.util.Node. */
public static byte[] props(Map<String, String> map) {
    Properties properties = new Properties();
    map.forEach((key, value) -> properties.put(key, value));
    try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
        Errors.rethrow().run(() -> properties.store(output, ""));
        return output.toByteArray();
    } catch (IOException e) {
        throw Errors.asRuntime(e);
    }/*from   w ww . j a  va2 s.  c  o m*/
}

From source file:com.rdonasco.security.utils.EncryptionUtil.java

private static void generateEncryptedPassword(String propsFile, String outFile) throws Exception {
    FileInputStream fis = null;/*from www.  ja v  a2  s .c om*/
    FileOutputStream fos = null;
    try {
        fis = new FileInputStream(new File(propsFile));
        Properties props = new Properties();
        props.load(fis);
        String stringToEncrypt = props.getProperty("password");
        String passphrase = props.getProperty("passphrase");
        System.out.println("passphrase:<" + passphrase + ">");
        System.out.println("encrypting " + stringToEncrypt);
        String encrypted = EncryptionUtil.encryptWithPassword(stringToEncrypt, passphrase);
        System.out.println("encrypted:" + encrypted);
        String decrypted = EncryptionUtil.decryptWithPassword(encrypted, passphrase);
        System.out.println("decrypted:" + decrypted);
        if (!stringToEncrypt.equals(decrypted)) {
            throw new Exception(
                    "password cannot be decrypted properly, please choose another password or change passphrase.");
        }
        Properties keyProperties = new Properties();
        keyProperties.put("encrypted", encrypted);
        fos = new FileOutputStream(new File(outFile));
        keyProperties.store(fos,
                "last updated " + new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss").format(new Date()));

    } finally {
        if (null != fis) {
            try {
                fis.close();
            } catch (IOException ex) {
                LOG.log(Level.SEVERE, ex.getMessage(), ex);
            }
        }
        if (null != fos) {
            try {
                fos.close();
            } catch (IOException ex) {
                LOG.log(Level.SEVERE, ex.getMessage(), ex);
            }
        }
    }
}

From source file:model.PayloadSequences.java

/**
 * Encapsulation metadata is stored between the START_SEQ and
 * END_HEADER_SEQ. It is a serialised {@link Properties} file.
 * /*from ww w .  ja  v a 2s  .com*/
 * @param properties
 * @return byte array representation of preferences
 */
public static byte[] getEncapsulationMetadataBytes(Properties properties) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        properties.store(outputStream, null);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outputStream.toByteArray();
}