<commit_before>package org.apache.commons.configuration;

/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed 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.
 */

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.lang.StringUtils;

/**
 * This is the "classic" Properties loader which loads the values from
 * a single or multiple files (which can be chained with "include =".
 * All given path references are either absolute or relative to the 
 * file name supplied in the Constructor.
 * <p>
 * In this class, empty PropertyConfigurations can be built, properties
 * added and later saved. include statements are (obviously) not supported
 * if you don't construct a PropertyConfiguration from a file.
 * <p>
 * If you want to use the getResourceAsStream() trick to load your 
 * resources without an absolute path, please take a look at the
 * ClassPropertiesConfiguration which is intended to be used for this.
 * 
 * @version $Id: PropertiesConfiguration.java,v 1.5 2004/03/28 14:43:04 epugh Exp $
 */
public class PropertiesConfiguration
        extends BasePropertiesConfiguration
        implements Configuration
{
    

    /** File separator. */
    protected String fileSeparator = System.getProperty("file.separator");

    /** 
     * The name of the file to be loaded.  This is used in conjuction with
     * the load method. */
    protected String fileName = null;

    /**
     * Creates an empty PropertyConfiguration object which can be
     * used to synthesize a new Properties file by adding values and
     * then saving(). An object constructed by this C'tor can not be 
     * tickled into loading included files because it cannot supply a
     * base for relative includes.
     */
    public PropertiesConfiguration()
    {
        setIncludesAllowed(false);
    }


    /**
     * Creates and loads the extended properties from the specified file.
     * The specified file can contain "include = " properties which then
     * are loaded and merged into the properties.
     *
     * @param fileName The name of the Properties File to load.
     * @throws IOException Error while loading the properties file
     */
    public PropertiesConfiguration(String fileName) throws ConfigurationException
    {

        load(fileName);
    }

    /**
     * Load the properties from the fileName set by setFileName 
     *
     * @throws IOException
     */
    public void load() throws ConfigurationException
    {
        load(getFileName());
    }

    /**
     * Load the properties from the given fileName
     *
     * @param fileName A properties file to load
     * @throws IOException
     */
    public void load(String fileName) throws ConfigurationException
    {
    	try {
    		load(getPropertyStream(fileName));
    	}
    	catch (IOException ioe){
    		throw new ConfigurationException("Could not load from file " + fileName,ioe);
    	}
    }

    /**
     * Gets a resource relative to the supplied base path. If the passed in
     * resource name is absolute, it is used directly.
     *
     * @param resourceName The resource Name
     * @return An Input Stream
     * @throws IOException Error while loading the properties file
     */
    protected InputStream getPropertyStream(String resourceName) throws IOException<commit_msg>Bug in closing stream spotted by <NAME>.<commit_after>package org.apache.commons.configuration;

/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed 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.
 */

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.lang.StringUtils;

/**
 * This is the "classic" Properties loader which loads the values from
 * a single or multiple files (which can be chained with "include =".
 * All given path references are either absolute or relative to the 
 * file name supplied in the Constructor.
 * <p>
 * In this class, empty PropertyConfigurations can be built, properties
 * added and later saved. include statements are (obviously) not supported
 * if you don't construct a PropertyConfiguration from a file.
 * <p>
 * If you want to use the getResourceAsStream() trick to load your 
 * resources without an absolute path, please take a look at the
 * ClassPropertiesConfiguration which is intended to be used for this.
 * 
 * @version $Id: PropertiesConfiguration.java,v 1.6 2004/03/28 15:34:23 epugh Exp $
 */
public class PropertiesConfiguration
        extends BasePropertiesConfiguration
        implements Configuration
{
    

    /** File separator. */
    protected String fileSeparator = System.getProperty("file.separator");

    /** 
     * The name of the file to be loaded.  This is used in conjuction with
     * the load method. */
    protected String fileName = null;

    /**
     * Creates an empty PropertyConfiguration object which can be
     * used to synthesize a new Properties file by adding values and
     * then saving(). An object constructed by this C'tor can not be 
     * tickled into loading included files because it cannot supply a
     * base for relative includes.
     */
    public PropertiesConfiguration()
    {
        setIncludesAllowed(false);
    }


    /**
     * Creates and loads the extended properties from the specified file.
     * The specified file can contain "include = " properties which then
     * are loaded and merged into the properties.
     *
     * @param fileName The name of the Properties File to load.
     * @throws IOException Error while loading the properties file
     */
    public PropertiesConfiguration(String fileName) throws ConfigurationException
    {

        load(fileName);
    }

    /**
     * Load the properties from the fileName set by setFileName 
     *
     * @throws IOException
     */
    public void load() throws ConfigurationException
    {
        load(getFileName());
    }

    /**
     * Load the properties from the given fileName
     *
     * @param fileName A properties file to load
     * @throws IOException
     */
    public void load(String fileName) throws ConfigurationException
    {
    	try {
    	    InputStream is = getPropertyStream(fileName);
    		load(is);
    		is.close();
    	}
    	catch (IOException ioe){
    		throw new ConfigurationException("Could not load from file " + fileName,ioe);
    	}
    }

    /**
     * Gets a resource relative to the supplied base path. If the passed in
     * resource name is absolute, it is used directly.
     *
     * @param resourceName The resource Name
     * @return An Input Stream
     * @throws IOException Error while loading the properties file
     */
    protected InputStream getPropertyStream(String resourceName) throws IOException
{'fraction_non_alphanumeric': 0.06816154924194165, 'fraction_numerical': 0.007134666836539687, 'mean_word_length': 3.019457245263697, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '830591', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1903, 'n_words': 873}