org.crsh.console.jline.internal.Configuration Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2002-2012, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* http://www.opensource.org/licenses/bsd-license.php
*/
package jline.internal;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Properties;
import static jline.internal.Preconditions.checkNotNull;
/**
* Provides access to configuration values.
*
* @author Jason Dillon
* @author Guillaume Nodet
* @since 2.4
*/
public class Configuration
{
/**
* System property which can point to a file or URL containing configuration properties to load.
*
* @since 2.7
*/
public static final String JLINE_CONFIGURATION = "jline.configuration";
/**
* Default configuration file name loaded from user's home directory.
*/
public static final String JLINE_RC = ".jline.rc";
private static volatile Properties properties;
private static Properties initProperties() {
URL url = determineUrl();
Properties props = new Properties();
try {
loadProperties(url, props);
}
catch (IOException e) {
// debug here instead of warn, as this can happen normally if default jline.rc file is missing
Log.debug("Unable to read configuration from: ", url, e);
}
return props;
}
private static void loadProperties(final URL url, final Properties props) throws IOException {
Log.debug("Loading properties from: ", url);
InputStream input = url.openStream();
try {
props.load(new BufferedInputStream(input));
}
finally {
try {
input.close();
}
catch (IOException e) {
// ignore
}
}
if (Log.DEBUG) {
Log.debug("Loaded properties:");
for (Map.Entry
© 2015 - 2024 Weber Informatics LLC | Privacy Policy