/**
* The Class SystemResource.
*/
public final class SystemResource {
/** The properties. */
private Properties properties = null;
/** The Constant FILENAME. */
public static final String FILENAME = "properties/sys-resource.properties";
/** The instance. */
private static SystemResource instance = null;
/**
* Instantiates a new system resource.
*/
private SystemResource() {
try {
readProperties(FILENAME);
} catch (AdsSystemException e) {
AdsLogger.error(e);
}
}
/**
* Gets the single instance of SystemResource.
*
* @return single instance of SystemResource
*/
public static SystemResource getInstance() {
if (instance == null) {
instance = new SystemResource();
}
return instance;
}
/**
* Get.
*
* @param key the key
* @return the string
*/
public String get(String key) {
if (properties.containsKey(key)) {
return properties.getProperty(key);
}
return null;
}
/**
* Read properties.
*
* @param file the file
* @throws AdsSystemException the ads system exception
*/
protected void readProperties(String file) throws AdsSystemException {
// 1. init?
if (properties != null) {
return;
}
// 3. first time
properties = new Properties();
// 4. read
InputStream in = this.getClass().getClassLoader().getResourceAsStream(file);
// 6. load file
try {
properties.load(in);
} catch (IOException e) {
throw new AdsSystemException(e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
throw new AdsSystemException(e);
}
}
}
}
}
* The Class SystemResource.
*/
public final class SystemResource {
/** The properties. */
private Properties properties = null;
/** The Constant FILENAME. */
public static final String FILENAME = "properties/sys-resource.properties";
/** The instance. */
private static SystemResource instance = null;
/**
* Instantiates a new system resource.
*/
private SystemResource() {
try {
readProperties(FILENAME);
} catch (AdsSystemException e) {
AdsLogger.error(e);
}
}
/**
* Gets the single instance of SystemResource.
*
* @return single instance of SystemResource
*/
public static SystemResource getInstance() {
if (instance == null) {
instance = new SystemResource();
}
return instance;
}
/**
* Get.
*
* @param key the key
* @return the string
*/
public String get(String key) {
if (properties.containsKey(key)) {
return properties.getProperty(key);
}
return null;
}
/**
* Read properties.
*
* @param file the file
* @throws AdsSystemException the ads system exception
*/
protected void readProperties(String file) throws AdsSystemException {
// 1. init?
if (properties != null) {
return;
}
// 3. first time
properties = new Properties();
// 4. read
InputStream in = this.getClass().getClassLoader().getResourceAsStream(file);
// 6. load file
try {
properties.load(in);
} catch (IOException e) {
throw new AdsSystemException(e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
throw new AdsSystemException(e);
}
}
}
}
}