// Path: pie-core/src/main/java/com/coverity/security/pie/util/IOUtil.java
// public class IOUtil {
//     public static void closeSilently(Closeable closeable) {
//         if (closeable != null) {
//             try {
//                 closeable.close();
//             } catch (IOException e) {
//                 // Do nothing
//             }
//         }
//     }
//     
//     public static String readFile(File file) throws IOException {
//         return toString(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
//     }
//     public static String readFile(String file) throws IOException {
//         return toString(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
//     }
//     public static String readFile(URL file) throws IOException {
//         return toString(file.openStream());
//     }
//     
//     public static String toString(InputStream is) throws IOException {
//         try {
//             return toString(new InputStreamReader(is, StandardCharsets.UTF_8));
//         } finally {
//             closeSilently(is);
//         }
//     }
//     public static String toString(Reader reader) throws IOException {
//         StringBuilder sb = new StringBuilder();
//         try {
//             char buffer[] = new char[4096];
//             int n;
//             while ((n = reader.read(buffer)) > 0) {
//                 sb.append(buffer, 0, n);
//             }
//             reader.close();
//         } catch (IOException e) {
//             closeSilently(reader);
//             throw e;
//         }
//         return sb.toString();
//     }
//     
//     
//     public static void writeFile(File file, String content) throws IOException {
//         writeFile(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8), content);
//     }
//     private static void writeFile(Writer fw, String content) throws IOException {
//         try {
//             fw.write(content);
//             fw.close();
//         } catch (IOException e) {
//             closeSilently(fw);
//             throw e;
//         }
//     }
//     
// }


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import com.coverity.security.pie.util.IOUtil;
package com.coverity.security.pie.core;



/**
 * Configuration for PIE. This abstracts reading in the pieConfig.properties file and returning configuration
 * directives.
 */
public class PieConfig {

    private final Properties properties = new Properties();

    public PieConfig() {
        loadProps(this.getClass().getClassLoader().getResource("pieConfig.default.properties"));
        File propFile = new File("pieConfig.properties");
        if (propFile.exists()) {
            try {
                loadProps(propFile.toURI().toURL());
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        } else {
            loadProps(this.getClass().getClassLoader().getResource("pieConfig.properties"));
        }
    }
    public PieConfig(URL propertiesUrl) {
        loadProps(this.getClass().getClassLoader().getResource("pieConfig.default.properties"));
        loadProps(propertiesUrl);
    }
    private void loadProps(URL propertiesUrl) {
        if (propertiesUrl != null) {
            InputStream is = null;
            try {
                is = propertiesUrl.openStream();
                if (is != null) {
                    properties.load(is);
                    is.close();
                }
            } catch (IOException e) {
// Path: pie-core/src/main/java/com/coverity/security/pie/util/IOUtil.java
// public class IOUtil {
//     public static void closeSilently(Closeable closeable) {
//         if (closeable != null) {
//             try {
//                 closeable.close();
//             } catch (IOException e) {
//                 // Do nothing
//             }
//         }
//     }
//     
//     public static String readFile(File file) throws IOException {
//         return toString(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
//     }
//     public static String readFile(String file) throws IOException {
//         return toString(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
//     }
//     public static String readFile(URL file) throws IOException {
//         return toString(file.openStream());
//     }
//     
//     public static String toString(InputStream is) throws IOException {
//         try {
//             return toString(new InputStreamReader(is, StandardCharsets.UTF_8));
//         } finally {
//             closeSilently(is);
//         }
//     }
//     public static String toString(Reader reader) throws IOException {
//         StringBuilder sb = new StringBuilder();
//         try {
//             char buffer[] = new char[4096];
//             int n;
//             while ((n = reader.read(buffer)) > 0) {
//                 sb.append(buffer, 0, n);
//             }
//             reader.close();
//         } catch (IOException e) {
//             closeSilently(reader);
//             throw e;
//         }
//         return sb.toString();
//     }
//     
//     
//     public static void writeFile(File file, String content) throws IOException {
//         writeFile(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8), content);
//     }
//     private static void writeFile(Writer fw, String content) throws IOException {
//         try {
//             fw.write(content);
//             fw.close();
//         } catch (IOException e) {
//             closeSilently(fw);
//             throw e;
//         }
//     }
//     
// }


// Path: pie-core/src/main/java/com/coverity/security/pie/core/PieConfig.java
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import com.coverity.security.pie.util.IOUtil;

package com.coverity.security.pie.core;



/**
 * Configuration for PIE. This abstracts reading in the pieConfig.properties file and returning configuration
 * directives.
 */
public class PieConfig {

    private final Properties properties = new Properties();

    public PieConfig() {
        loadProps(this.getClass().getClassLoader().getResource("pieConfig.default.properties"));
        File propFile = new File("pieConfig.properties");
        if (propFile.exists()) {
            try {
                loadProps(propFile.toURI().toURL());
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        } else {
            loadProps(this.getClass().getClassLoader().getResource("pieConfig.properties"));
        }
    }
    public PieConfig(URL propertiesUrl) {
        loadProps(this.getClass().getClassLoader().getResource("pieConfig.default.properties"));
        loadProps(propertiesUrl);
    }
    private void loadProps(URL propertiesUrl) {
        if (propertiesUrl != null) {
            InputStream is = null;
            try {
                is = propertiesUrl.openStream();
                if (is != null) {
                    properties.load(is);
                    is.close();
                }
            } catch (IOException e) {
                IOUtil.closeSilently(is);