Example usage for java.util Properties replaceAll

List of usage examples for java.util Properties replaceAll

Introduction

In this page you can find the example usage for java.util Properties replaceAll.

Prototype

@Override
    public synchronized void replaceAll(BiFunction<? super Object, ? super Object, ?> function) 

Source Link

Usage

From source file:de.loercher.localpress.commons.LocalPressProperties.java

private void initProperties(String propertyFile, String securePropertyFile) {
    InputStream in1 = LocalPressProperties.class.getResourceAsStream(propertyFile);
    try {//from w  w w. j  a  v  a  2  s  .c  o  m
        prop.load(in1);
    } catch (Exception ex) {
        InputStream hin = null;
        try {
            hin = new FileInputStream(propertyFile);
            prop.load(hin);
        } catch (FileNotFoundException ex1) {
            log.error(
                    "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                    ex1);
        } catch (IOException ex1) {
            log.error(
                    "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                    ex1);
        } finally {
            if (hin != null) {
                try {
                    hin.close();
                } catch (IOException ex1) {
                    log.error(
                            "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                            ex1);
                }
            }
        }
    } finally {
        try {
            if (in1 != null) {
                in1.close();
            }
        } catch (IOException ex) {
            log.error(
                    "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                    ex);
        }
    }

    // load the obfuscated properties from secure.properties by using the obfuscation key
    InputStream in = LocalPressProperties.class.getResourceAsStream(securePropertyFile);
    try {
        Properties obfuscatedProperties = new Properties();
        obfuscatedProperties.load(in);

        obfuscatedProperties.replaceAll((a, b) -> helper.unobfuscateString((String) b));

        prop.putAll(obfuscatedProperties);
    } catch (Exception ex) {
        InputStream hin = null;
        try {
            hin = new FileInputStream(securePropertyFile);
            Properties obfuscatedProperties = new Properties();
            obfuscatedProperties.load(hin);

            obfuscatedProperties.replaceAll((a, b) -> helper.unobfuscateString((String) b));

            prop.putAll(obfuscatedProperties);
        } catch (FileNotFoundException ex1) {
            log.error(
                    "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                    ex);
        } catch (IOException ex1) {
            log.error(
                    "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                    ex);
        } finally {
            if (hin != null) {
                try {
                    hin.close();
                } catch (IOException ex1) {
                    log.error(
                            "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                            ex1);
                }
            }
        }
    } finally {
        try {
            if (in1 != null) {
                in1.close();
            }
        } catch (IOException ex) {
            log.error(
                    "Unexpected error occured on loading file /config/rating.properties. Loading unsuccessful.",
                    ex);
        }
    }

    log.info("Imported Properties: ");
    for (Object key : prop.keySet()) {
        log.info(key + ": " + prop.get(key));
    }
}