<commit_before>/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
* @author <NAME>
* @version $Revision$
*/

package java.security;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.harmony.security.Util;
import org.apache.harmony.security.fortress.Engine;
import org.apache.harmony.security.fortress.PolicyUtils;
import org.apache.harmony.security.fortress.SecurityAccess;
import org.apache.harmony.security.fortress.Services;
import org.apache.harmony.security.internal.nls.Messages;

/**
 * For access to security providers and properties.
 */
public final class Security {

    // Security properties
    private static Properties secprops = new Properties();

    // static initialization
    // - load security properties files
    // - load statically registered providers
    // - if no provider description file found then load default providers
    static {
        AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
            public Void run() {
                boolean loaded = false;
                File f = new File(System.getProperty("java.home") //$NON-NLS-1$
                        + File.separator + "lib" + File.separator //$NON-NLS-1$
                        + "security" + File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
                if (f.exists()) {
                    try {
                        FileInputStream fis = new FileInputStream(f);
                        InputStream is = new BufferedInputStream(fis);
                        secprops.load(is);
                        loaded = true;
                        is.close();
                    } catch (IOException e) {
//                        System.err.println("Could not load Security properties file: "
//                                        + e);
                    }
                }

                if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    String securityFile = System.getProperty("java.security.properties"); //$NON-NLS-1$
                    if (securityFile != null) {
                        if (securityFile.startsWith("=")) { // overwrite //$NON-NLS-1$
                            secprops = new Properties();
                            loaded = false;
                            securityFile = securityFile.substring(1);
                        }
                        try {
                            securityFile = PolicyUtils.expand(securityFile, System.getProperties());
                        } catch (PolicyUtils.ExpansionFailedException e) {
//                            System.err.println("Could not load custom Security properties file "
//                                    + securityFile +": " + e);
                        }
                        f = new File(securityFile);
                        InputStream is;
                        try {
                            if (f.exists()) {
                                FileInputStream fis = new FileInputStream(f);
                                is = new BufferedInputStream(fis);
                            } else {
                                URL url = new URL(securityFile);
                                is = new BufferedInputStream(url.openStream());
                            }
                            secprops.load(is);
                            loaded = true;
                            is.close();<commit_msg>Use an InputStreamReader to read properties files to ensure the correct charater conversions occur. No need to buffer the stream at this end as Properties.load() buffers the stream itself anyway.<commit_after>/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
* @author <NAME>
* @version $Revision$
*/

package java.security;

import java.io.InputStreamReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.harmony.security.Util;
import org.apache.harmony.security.fortress.Engine;
import org.apache.harmony.security.fortress.PolicyUtils;
import org.apache.harmony.security.fortress.SecurityAccess;
import org.apache.harmony.security.fortress.Services;
import org.apache.harmony.security.internal.nls.Messages;

/**
 * For access to security providers and properties.
 */
public final class Security {

    // Security properties
    private static Properties secprops = new Properties();

    // static initialization
    // - load security properties files
    // - load statically registered providers
    // - if no provider description file found then load default providers
    static {
        AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
            public Void run() {
                boolean loaded = false;
                File f = new File(System.getProperty("java.home") //$NON-NLS-1$
                        + File.separator + "lib" + File.separator //$NON-NLS-1$
                        + "security" + File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
                if (f.exists()) {
                    try {
                        FileInputStream fis = new FileInputStream(f);
                        InputStreamReader is = new InputStreamReader(fis);
                        secprops.load(is);
                        loaded = true;
                        is.close();
                    } catch (IOException e) {
//                        System.err.println("Could not load Security properties file: "
//                                        + e);
                    }
                }

                if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    String securityFile = System.getProperty("java.security.properties"); //$NON-NLS-1$
                    if (securityFile != null) {
                        if (securityFile.startsWith("=")) { // overwrite //$NON-NLS-1$
                            secprops = new Properties();
                            loaded = false;
                            securityFile = securityFile.substring(1);
                        }
                        try {
                            securityFile = PolicyUtils.expand(securityFile, System.getProperties());
                        } catch (PolicyUtils.ExpansionFailedException e) {
//                            System.err.println("Could not load custom Security properties file "
//                                    + securityFile +": " + e);
                        }
                        f = new File(securityFile);
                        InputStreamReader is;
                        try {
                            if (f.exists()) {
                                FileInputStream fis = new FileInputStream(f);
                                is = new InputStreamReader(fis);
                            } else {
                                URL url = new URL(securityFile);
                                is = new InputStreamReader(url.openStream());
                            }
                            secprops.load(is);
                            loaded = true;
                            is.close();
{'fraction_non_alphanumeric': 0.09374330404971074, 'fraction_numerical': 0.0029997857295907433, 'mean_word_length': 1.672487832808474, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5715987', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2175, 'n_words': 652}