Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
refact props to try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
kosteman committed Dec 19, 2016
1 parent 757c259 commit 47b8fe0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
24 changes: 10 additions & 14 deletions src/main/java/ru/sbtqa/tag/qautils/properties/Props.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@ public class Props {
public Props() throws IOException {
System.setProperty("logback.configurationFile", "config/logback.xml");
String sConfigFile = System.getProperty("BDDConfigFile", "config/application.properties");
log.info("Loading properties from: " + sConfigFile);
//first try to load properties from resources
InputStream in = Props.class.getClassLoader().getResourceAsStream(sConfigFile);
properties = new Properties();
//if failed try to load from filesystem
try {
if (in == null) {
in = new FileInputStream(sConfigFile);
}
properties.load(in);
} finally {
if (in != null) {
in.close();
log.info("Loading properties from: " + sConfigFile);
try (InputStream streamFromResources = Props.class.getClassLoader().getResourceAsStream(sConfigFile);
InputStream streamFromFilesystem = new FileInputStream(sConfigFile)) {
//first try to load properties from resources. If failed try to load from filesystem
if (streamFromResources != null) {
properties.load(streamFromResources);
} else {
properties.load(streamFromFilesystem);
}
}
}

/**
* Creates single instance of Props class or returns already created
*
Expand Down Expand Up @@ -100,7 +96,7 @@ public static String get(String prop, String defaultValue) {
if (value.isEmpty()) {
return defaultValue;
}

return value;
} else {
return null;
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/ru/sbtqa/tag/qautils/reflect/FieldUtilsExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
public class FieldUtilsExt extends org.apache.commons.lang3.reflect.FieldUtils {

/**
* It is like
* {@link org.apache.commons.lang3.reflect.FieldUtils} getAllFieldsList but
* extended by inherited declared fields only. Very fast.
* It is like {@link org.apache.commons.lang3.reflect.FieldUtils}
* getAllFieldsList but extended by inherited declared fields only.
*
* @param clazz the class to reflect
* @return {@link List} a list of fields
Expand All @@ -35,9 +34,9 @@ public static List<Field> getDeclaredFieldsWithInheritance(Class clazz) {
}

/**
* It is like
* {@link org.apache.commons.lang3.reflect.FieldUtils} getAllFieldsList but
* extended by inherited declared fields only. Very fast.
* It is like {@link org.apache.commons.lang3.reflect.FieldUtils}
* getAllFieldsList but extended by inherited declared fields only. Very
* fast.
*
* @param object the class to reflect
* @return {@link List} a list of fields
Expand Down

0 comments on commit 47b8fe0

Please sign in to comment.