
devutility.internal.util.PropertiesUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Utilities for Java development
package devutility.internal.util;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import devutility.internal.data.BeanUtils;
import devutility.internal.io.ResourcesUtils;
import devutility.internal.lang.ClassHelper;
import devutility.internal.lang.StringHelper;
import devutility.internal.lang.models.EntityField;
public class PropertiesUtils {
/**
* Get properties.
* @param propertiesFile: Properties file name.
* @return Properties
*/
public static Properties getProperties(String propertiesFile) {
InputStream inputStream = PropertiesUtils.class.getClassLoader().getResourceAsStream(propertiesFile);
return getProperties(inputStream);
}
/**
* Find out the properties file by default order and load it.
* @param propertiesFile: Properties file name.
* @return Properties
* @throws URISyntaxException
* @throws FileNotFoundException
*/
public static Properties getPropertiesByDefaultOrder(String propertiesFile) throws URISyntaxException, FileNotFoundException {
String path = ResourcesUtils.getPathByDefaultOrder(propertiesFile);
if (path == null) {
return null;
}
InputStream inputStream = new FileInputStream(path);
return getProperties(inputStream);
}
/**
* Get properties
* @param inputStream: InputStream of properties file
* @return Properties
*/
public static Properties getProperties(InputStream inputStream) {
try (InputStream inStream = inputStream) {
Properties properties = new Properties();
properties.load(inStream);
return properties;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Check one properties object whether contains prefix.
* @param properties: Properties object
* @param prefix: Prefix of property key
* @return boolean
*/
public static boolean containsPrefix(Properties properties, String prefix) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy