Load Properties File

@param path relative path to the config file
@return Boolean whether config file loaded or not
@throws IOException May throw IOException if it cannot open configs file
353720
public Boolean loadPropertiesFile(String path) throws IOException
    {
        Properties prop = new Properties();
        InputStream input = null;

        try {

            input = new FileInputStream(path);
            prop.load(input);

            for(String key : prop.stringPropertyNames()) {
                String value = prop.getProperty(key);
                configs.put(key, value);
            }

            return true;
        } catch (IOException ex) {
            return false;
        }
    }
937695
def load_config(paths=DEFAULT_CONFIG_PATHS):
    
    config = Config()
    for path in paths:
        if os.path.isfile(path):
            config.load_pyfile(path)

    return config
1331913
function loadConfig(path) {
  try {
    var configJSON = JSON.parse(fs.readFileSync(process.cwd() + "/" + path));
    console.log("Config file detected: " + path)
    return configJSON;
  }
  catch(e) {
    console.log("Config file: " + e.toString())
  }
}
421590
public function loadConfig($path)
    {
        //add extension to the config file
        $path = sprintf("%s.%s", $path, $this->config_file_extension);

        //lets try loading the config file data
        return $this->loader->load($path);
    }
732933
public static Properties loadProperties(Class<?> clazz, String fileName) throws IOException {
        Properties properties = new Properties();
        try (InputStream is = clazz.getClassLoader().getResourceAsStream(fileName)) {
            properties.load(is);
        }
        return properties;
    }
79089
public static Properties loadProperties(File file) throws IOException {
        FileInputStream finp = new FileInputStream(file);
        try {
            Properties p = new Properties();
            p.load(finp);
            return p;
        } finally {
            ArchiveUtils.closeQuietly(finp);
        }
    }
837806
public static Properties loadProperties(String propertyFilePath){
		Properties prop = new Properties();
		InputStream is = null;
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		try {
			is = cl.getResourceAsStream(propertyFilePath);
			Assert.notNull(is, "Failed to obtain InputStream for " + propertyFilePath);
			prop.load(is);
			resolveSystemPropertyPlaceholders(prop);
		} 
		catch (Exception e) {
			throw new IllegalStateException("Failed to load configuration properties: " + propertyFilePath, e);
		} 
		finally {
			try {
				is.close();
			} catch (Exception e2) {
				// ignore
			}
		}
		return prop;
	}
578599
private function loadFromFile($path)
    {
        if ( ! is_file($path)) {
            return;
        }
        
        $config = require_once $path;
        
        if (is_array($config)) {
            $this->config = $config;
        }
    }
1089387
public void readResources(String path) throws IOException {
		Enumeration<URL> resources =
				getClass().getClassLoader().getResources(path);

		if (!resources.hasMoreElements()) {
			throw new IllegalArgumentException(String.format("File %s was not found on classpath", path));
		}

		Yaml yaml = new Yaml();
		while (resources.hasMoreElements()) {
			appendData(yaml.loadAs(resources.nextElement().openStream(), Data.class));
		}
	}
1093284
private synchronized void loadProperties()
	{
		// If multiple threads are waiting to invoke this method only allow
		// the first one to do so. The rest should just return since the first
		// thread through took care of loading the properties.
		try
		{
			
			this.file = null;
			
			boolean alwaysReload = this.isAlwaysReload();

			boolean useFormatting = this.isUseFormatting();
	
			String filePath = getSystemPropertyFile();
			if (filePath != null && filePath.length() > 0)
			{
				// System.out.println("CONFIG: LOADING CONFIG properties from "+
				// file);
				this.file = Paths.get(filePath).toFile();
				FileInputStream fis = new FileInputStream(file);

				try
				{
					properties = new Properties();
					// Load the properties object from the properties file
					properties.load(fis);
					// System.out.println("CONFIG: FINISHED LOADING CONFIG
					// properties from "+
					// file);

					configSourceLocation = file.getAbsolutePath();
				}
				catch (Exception e)
				{
					e.printStackTrace();
					throw new ConfigException(e.toString());
				}
				finally
				{
					if (fis != null)
						fis.close(); // Always close the file, even on exception

				}

			}
			else
			{
				properties = new Properties();

				try
				{
					String bundleName = getBundleName();

					// try to get properties from resource bundle
					ResourceBundle rb = ResourceBundle.getBundle(bundleName);

					URL url = Config.class.getResource(bundleName + ".properties");

					if (url != null)
						configSourceLocation = url.toString();
					else
						configSourceLocation = bundleName + ".properties";

					Enumeration<?> keys = rb.getKeys();

					Object k = null;

					while (keys.hasMoreElements())
					{

						k = keys.nextElement();

						properties.put(k, rb.getString(k + ""));

					}
				} // end els load from resource bundle
				catch (MissingResourceException e)
				{
				}
			}//end else
			
			

			//Determine global settings
			String reloadBool = properties.getProperty(Config.class.getName() + ".alwaysReload");

			if (reloadBool == null || reloadBool.length() == 0)
			{

				// throw new ConfigException("System property
				// "+Constants.ALWAY_RELOAD_PROP+" is not set.");

				alwaysReload = false;

			}
			else
			{
				alwaysReload = Boolean.valueOf(reloadBool).booleanValue();
			}

			this.setAlwaysReload(alwaysReload);

			// Merge SystemProperteis
			mergeSystemProperties = Boolean
					.valueOf(properties.getProperty(Config.class.getName() + ".mergeSystemProperties", "true"))
					.booleanValue();

			if (mergeSystemProperties)
			{
				// add system properties
				properties.putAll((Properties)System.getProperties().clone());
			}

			// Envinronment SystemProperteis
			mergeEnvProperties = Boolean
					.valueOf(properties.getProperty(Config.class.getName() + ".mergeEnvProperties", "true"))
					.booleanValue();

			if (mergeEnvProperties)
			{
				// add env properties
				properties.putAll(System.getenv());
			}

			// process formatting
			String propName = Config.class.getName() + ".useFormatting";
			String useFormattingText = properties.getProperty(propName);

			// System.out.println("CONFIG:
			// "+propName+"="+useFormattingText);

			if (useFormattingText == null || useFormattingText.length() == 0)
			{

				// throw new ConfigException("System property
				// "+Constants.ALWAY_RELOAD_PROP+" is not set.");

				useFormatting = false;

			}
			else
			{
				useFormatting = Boolean.valueOf(useFormattingText).booleanValue();
			}

			if (useFormatting)
			{
				// System.out.println("CONFIG: FORMATTING MAP CONFIG
				// properties ");
				// format map (note this can be an expensive operation)

				Text.formatMap(properties);
				// System.out.println("CONFIG: FORMATTED MAP CONFIG
				// properties ");
			}

			propName = Config.class.getName() + ".setSystemProperties";
			setSystemProperties = Boolean.valueOf(properties.getProperty(propName, "false")).booleanValue();

			// Set system properties with values from configuration
			if (setSystemProperties)
			{
				Set<Object> keySet = properties.keySet();
				String key;
				String sysProp;
				for (Iterator<Object> i = keySet.iterator(); i.hasNext();)
				{
					key = (String) i.next();
					sysProp = System.getProperty(key);

					if (sysProp != null && sysProp.length() > 0)
						continue; // do not override values

					// set system property
					System.setProperty(key, properties.getProperty(key));
				}
			}
			
			
			
		}
		catch (ConfigException e)
		{
			throw e;
		}
		catch (FileNotFoundException e)
		{
			throw new ConfigException(e.getMessage(), e);
		}
		catch (Exception e)
		{
			throw new ConfigException(e.getMessage(), e);
		}
		
		try
		{
			this.registry.notify(this.getClass().getName(), this);
		}
		catch(Exception e)
		{
			Debugger.printWarn(e);
		}
	}
712152
public void load(String config)
        throws IOException
    {
        _config=config;
        if(log.isDebugEnabled())log.debug("Load "+this+" from "+config);
        Properties properties = new Properties();
        Resource resource=Resource.newResource(config);
        properties.load(resource.getInputStream());

        Iterator iter = properties.entrySet().iterator();
        while(iter.hasNext())
        {
            Map.Entry entry = (Map.Entry)iter.next();

            String username=entry.getKey().toString().trim();
            String credentials=entry.getValue().toString().trim();
            String roles=null;
            int c=credentials.indexOf(',');
            if (c>0)
            {
                roles=credentials.substring(c+1).trim();
                credentials=credentials.substring(0,c).trim();
            }

            if (username!=null && username.length()>0 &&
                credentials!=null && credentials.length()>0)
            {
                put(username,credentials);
                if(roles!=null && roles.length()>0)
                {
                    StringTokenizer tok = new StringTokenizer(roles,", ");
                    while (tok.hasMoreTokens())
                        addUserToRole(username,tok.nextToken());
                }
            }
        }
    }
818181
public static Properties loadFromFile(String generalPath) {
		Properties p = new Properties();
		try (Reader reader = new InputStreamReader(URLResourceUtil.asStream(generalPath), Charsets.UTF_8)) {
			p.load(reader);
		} catch (IOException e) {
			logger.warn("Load property from " + generalPath + " failed", e);
		}
		return p;
	}
790134
public function loadFile($path) {
        $content = trim(file_read($path));
        $config = [];

        if ( ! empty($content)) {
            $config = json_decode($content, true);

            if ( ! is_array($config)) {;
                throw new InvalidConfigFormatException(
                    s('JsonConfigDriver expects config at path %s to be a valid json file.', $path)
                );
            }
        }

        return $config;
    }
682732
function loadFile(path) {
    if ( config.asReference && config.asReference.loadFile ) {
      return config.asReference.loadFile( path );
    } else if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
      var fs = require.nodeRequire('fs');
      var file = fs.readFileSync(path, 'utf8');
      if (file.indexOf('\uFEFF') === 0)
        return file.substring(1);
      return file;
    }
    else {
      var file = new java.io.File(path),
        lineSeparator = java.lang.System.getProperty("line.separator"),
        input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), 'utf-8')),
        stringBuffer, line;
      try {
        stringBuffer = new java.lang.StringBuffer();
        line = input.readLine();
        if (line && line.length() && line.charAt(0) === 0xfeff)
          line = line.substring(1);
        stringBuffer.append(line);
        while ((line = input.readLine()) !== null) {
          stringBuffer.append(lineSeparator).append(line);
        }
        return String(stringBuffer.toString());
      }
      finally {
        input.close();
      }
    }
  }
329210
def load(self, path):
        
        with open(path) as f:
            self.config = full_load(f)
            if self.config is None:
                sys.stderr.write("Warning: config file is empty!\n")
                self.config = {}
840872
private static void loadProperty(String filePath)
    {
        try (InputStream propertyStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(
                filePath);
                Reader propertyReader = new InputStreamReader(propertyStream, DEFAULT_CHARSET);)
        {
            Properties properties = new Properties();
            properties.load(propertyReader);
            propertiesMap.put(filePath, properties);
        }
        catch (Exception ex)
        {
            String errorPattern = "Property file load failed. Skip load. : PropertyFile={0}";
            logger.warn(MessageFormat.format(errorPattern, filePath), ex);
        }
    }
271792
public static Properties loadProperties(String filePath) throws MnoConfigurationException {
		Properties properties = new Properties();
		InputStream input = getInputStreamFromClassPathOrFile(filePath);
		try {
			properties.load(input);
		} catch (IOException e) {
			throw new MnoConfigurationException("Could not load properties file: " + filePath, e);
		} finally {
			IOUtils.closeQuietly(input);
		}
		return properties;
	}