Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCT...
If you think the Android project andro_auto_framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.imaginea.botbot.filereader;
/*fromwww.java2s.com*/import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
import org.testng.Assert;
publicclass PropertiesReader implements BaseReader {
Properties propLocator = new Properties();
@Override
publicvoid loadReaderFile(String filePath) {
File locatorFile = newFile(filePath);
try {
this.openFile(locatorFile);
}catch(Exception e){
System.out.println(e.toString());
Assert.fail("Unable to open file : " + filePath);
}
}
publicvoid openFile(File file) throws Exception {
boolean result = true;
HashMap<String, String> hm = new HashMap<String, String>();
FileInputStream fin= new FileInputStream(file);
if (propLocator.isEmpty()) {
try {
propLocator.load(fin);
} catch (IOException e) {
System.out.println(e.toString());
}
} else {
Properties tempProp = new Properties();
try {
tempProp.load(fin);
} catch (IOException e) {
System.out.println(e.toString());
}
for (Enumeration e = tempProp.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
if (propLocator.containsKey(key)) {
result = false;
hm.put(key, tempProp.getProperty(key, ""));
}
}
if (!result) {
thrownew Exception(
"Duplicate entries found in the properties file. Following are the values: \n"
+ hm.toString());
}else{
propLocator.load(fin);
}
}
}
@Override
publicvoid openFile(String fileName) {
File file= newFile(fileName);
try {
this.openFile(file);
}catch(Exception e){
System.out.println(e.toString());
}
}
@Override
public String getDataForKey(String key) {
String data=propLocator.getProperty(key, "");
if(data.equalsIgnoreCase("")){
Assert.fail("Key not found for property: "+ key);
}
return data;
}
@Override
publicvoid storeKeyValue(String locatorName, String newLocator) {
propLocator.setProperty(locatorName, newLocator);
}
@Override
publicvoid modifyValueForKey(String locatorName, String newLocatorValue) {
propLocator.setProperty(locatorName, newLocatorValue);
}
@Override
publicboolean supportsFileType(String filePath) {
if ((newFile(filePath).isFile()) && filePath.endsWith(".properties")) {
return true;
} else {
return false;
}
}
}