com.orctom.was.utils.PropertiesUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of was-util Show documentation
Show all versions of was-util Show documentation
Common Utils that talks to WebSphere used by was-maven-plugin and was-gradle-plugin
package com.orctom.was.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by CH on 3/19/14.
*/
public class PropertiesUtils {
public static Properties loadProperties(URL url) {
try {
return loadProperties(url.openStream());
} catch (Exception e) {
return null;
}
}
public static Properties loadProperties(File file) {
try {
return loadProperties(new FileInputStream(file));
} catch (Exception e) {
return null;
}
}
public static Properties loadProperties(InputStream is) {
try {
Properties properties = new Properties();
if (null != is) {
properties.load(is);
}
return properties;
} catch (IOException e) {
return null;
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
}
}
}
public static Map loadSectionedProperties(URL url) {
return loadSectionedProperties(url, null);
}
public static Map loadSectionedProperties(URL url, Properties defaultProps) {
try {
return loadSectionedProperties(url.openStream(), defaultProps);
} catch (Exception e) {
return null;
}
}
public static Map loadSectionedProperties(File file) {
return loadSectionedProperties(file, null);
}
public static Map loadSectionedProperties(File file, Properties defaultProps) {
try {
return loadSectionedProperties(new FileInputStream(file), defaultProps);
} catch (Exception e) {
return null;
}
}
public static Map loadSectionedProperties(InputStream is) {
return loadSectionedProperties(is, null);
}
public synchronized static Map loadSectionedProperties(InputStream is, Properties defaultProps) {
try {
SectionedProperties properties = new SectionedProperties(defaultProps);
if (null != is) {
properties.load(is);
}
return properties.getProperties();
} catch (IOException e) {
return null;
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
}
}
}
public static String resolve(String expression, Properties properties) {
return resolve(expression, properties, "{{", "}}");
}
public static String resolve(String expression, Properties properties, String startSign, String endSign) {
StringBuilder template = new StringBuilder(expression);
for (Map.Entry