<commit_before>package com.headwire.aemdc.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.headwire.aemdc.companion.Constants;


/**
 * Files and Dirs Util
 *
 * @author <NAME>, 15.11.2016
 */
public class FilesDirsUtil {

  private static final Logger LOG = LoggerFactory.getLogger(FilesDirsUtil.class);

  /**
   * Constructor
   *
   */
  private FilesDirsUtil() {
  }

  /**
   * Get properties from property file
   *
   * @param filepath
   *          - file path
   * @return properties object
   */
  public static Properties getProperties(final String filepath) {
    final Properties props = new Properties();
    InputStream input = null;

    try {
      input = new FileInputStream(filepath);
      if(input != null) {
        // load a properties file from class path
        props.load(input);
      }
    } catch (final IOException e) {
      LOG.error("Sorry, unable to find or read properties from file [{}].", filepath);
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (final IOException e) {
          LOG.error("Sorry, unable to close input stream from file [{}].", filepath);
        }
      }
    }
    return props;
  }

  /**
   * Get properties from property file from Context Class Loader
   *
   * @param filepath
   *          - file path
   * @return properties object
   */
  public static Properties getPropertiesFromContextClassLoader(final String filepath) {
    final Properties props = new Properties();
    InputStream input = null;

    try {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      input = cl.getResourceAsStream(filepath);
      if(input == null) {
        cl = FilesDirsUtil.class.getClassLoader();
        input = cl.getResourceAsStream(filepath);
      }
      if(input != null) {
        // load a properties file from class path
        props.load(input);
      }
    } catch (final IOException e) {
      LOG.error("Sorry, unable to find or read properties from file [{}].", filepath);
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (final IOException e) {
          LOG.error("Sorry, unable to close input stream from file {}.", filepath);
        }
      }
    }
    return props;<commit_msg>added error log message<commit_after>package com.headwire.aemdc.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.headwire.aemdc.companion.Constants;


/**
 * Files and Dirs Util
 *
 * @author <NAME>, 15.11.2016
 */
public class FilesDirsUtil {

  private static final Logger LOG = LoggerFactory.getLogger(FilesDirsUtil.class);

  /**
   * Constructor
   *
   */
  private FilesDirsUtil() {
  }

  /**
   * Get properties from property file
   *
   * @param filepath
   *          - file path
   * @return properties object
   */
  public static Properties getProperties(final String filepath) {
    final Properties props = new Properties();
    InputStream input = null;

    try {
      input = new FileInputStream(filepath);
      if(input != null) {
        // load a properties file from class path
        props.load(input);
      }
    } catch (final IOException e) {
      LOG.error("Sorry, unable to find or read properties from file [{}].", filepath);
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (final IOException e) {
          LOG.error("Sorry, unable to close input stream from file [{}].", filepath);
        }
      }
    }
    return props;
  }

  /**
   * Get properties from property file from Context Class Loader
   *
   * @param filepath
   *          - file path
   * @return properties object
   */
  public static Properties getPropertiesFromContextClassLoader(final String filepath) {
    final Properties props = new Properties();
    InputStream input = null;

    try {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      input = cl.getResourceAsStream(filepath);

      if (input == null) {
        cl = FilesDirsUtil.class.getClassLoader();
        input = cl.getResourceAsStream(filepath);
      }

      if (input != null) {
        // load a properties file from class path
        props.load(input);
      } else {
        LOG.error("Sorry, unable to find or read properties from file [{}].", filepath);
      }

    } catch (final IOException e) {
      LOG.error("Sorry, unable to find or read properties from file [{}].", filepath);
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (final IOException e) {
          LOG.error("Sorry, unable to close input stream from file {}.", filepath);
        }
      }
    }
    return props;
{'fraction_non_alphanumeric': 0.10999461690292482, 'fraction_numerical': 0.003947604521801543, 'mean_word_length': 2.607766990291262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5214039', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1565, 'n_words': 441}