Skip to content

Instantly share code, notes, and snippets.

@basgys
Created April 10, 2013 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basgys/5356952 to your computer and use it in GitHub Desktop.
Save basgys/5356952 to your computer and use it in GitHub Desktop.
BundleReader
package ch.hegarc.ig.clientscomptes.configuration;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;
/**
*
* @author basgys
*/
public class BundleReader {
Properties properties;
public BundleReader(Properties properties) {
this.properties = properties;
}
public String get(String key) {
return properties.getProperty(key);
}
public static BundleReader createReaderForBundle(String bundleName) {
return new BundleReader(read(find(bundleName)));
}
private static Properties read(String filePath) {
FileReader fileReader = null;
try {
fileReader = new FileReader(filePath);
Properties props = new Properties();
props.load(fileReader);
return props;
} catch (IOException ex) {
Logger.getLogger(BundleReader.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
private static String find(String fileName) {
StringBuilder sb = new StringBuilder();
String packageName = BundleReader.class.getPackage().getName();
String[] test = BundleReader.class.getPackage().getName().split(".");
String appPath = StringUtils.join(test, "/");
sb.append(appPath).append("/").append(fileName);
File file = new File(sb.toString());
return file.getAbsolutePath();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment