Skip to content

Instantly share code, notes, and snippets.

@basgys

basgys/gist:5356952

Created Apr 10, 2013
Embed
What would you like to do?
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
You can’t perform that action at this time.