Created 12-26-2016 09:14 AM
I want to use # symbol in config.properties .
I know that # is used for comment in config.properties but I want to use it as a part of keyword.
eg:
#google=google
#microsoft=microsoft
I need this for getting tweets having hashtag(#)of google.
Is this possible? If yes then how and if no then why?
Thanks in advance.
Created 12-27-2016 12:46 PM
Its working properly I have applied this logic
if (readConfiguration.getInstance() .getPropertyMap() .containsKey(word.replace("#", ""))) { String companyName = readConfiguration .getPropertyMap().get( word.replace("#", ""));
Thanks.
Created 12-26-2016 10:20 AM
instead of reading # keys from properties file why don you put null check in your producer or consumer and set this value there like this
if (properties.getProperty("#google") == null) { properties.setProperty("#google", "google"); }
Created 12-26-2016 12:12 PM
config.properties
yahoo=yahoo google=google
#google=google(This is actually what I want to do but I know its comment in config.properties file)
Read configuration.class
public class ReadConfiguration implements Serializable {
private static ReadConfiguration readConfiguration; private static HashMap<String, String> propertyMap;
public static HashMap<String, String> getPropertyMap() {
return propertyMap; }
private ReadConfiguration() { }
public static synchronized ReadConfiguration getInstance() { if (readConfiguration == null) { readConfiguration = new ReadConfiguration(); propertyMap = readConfiguration .readConfiguration("/configuration.properties"); } return readConfiguration;
}
public HashMap<String, String> readConfiguration(String path) throws NullPointerException { HashMap<String, String> propertyMap = new HashMap<String, String>();
InputStream input = null;
try {
input = ReadConfiguration.class.getResourceAsStream(path);// /configuration
Properties properties = new Properties();
properties.load(input);
Set<String> propertyNames = properties.stringPropertyNames();
for (String Property : propertyNames) {
Enumeration<?> e = properties.propertyNames();
while (e.hasMoreElements()) { String key = (String) e.nextElement();
String value = properties.getProperty(key);
propertyMap.put(Property, properties.getProperty(Property)); } } } catch (IOException ex) { ex.printStackTrace(); } return propertyMap; } }
kafka.class
if (nullHandler.checkNull(tweetAsMap .get(TwitterProcessingPipelineConstants.TEXT)))
{ String tweetTextAsString = tweetAsMap.get( "text").toString();
tweetBean.setText(tweetTextAsString); logger.info("The Text --> " + tweetTextAsString);
for (String word : tweetTextAsString .toLowerCase().split(" "))
{ if (readConfiguration.getInstance() .getPropertyMap().containsKey(word))
{ String companyName = readConfiguration .getPropertyMap().get(word);//
tweetBean.setCompanyName(companyName);
break;
} }
This is what we have done in read config class we are taking company name from config.properties without any special character we are able to get the desired output.But as mentioned above for # how I can get the desired output.
Thanks in advance.
Created 12-26-2016 12:32 PM
how many of this type(#google=google) of property you are going to have in your applicaiton, if these are fews then you can put in your ReadConfiguration while building propertyMap.
Created 12-27-2016 04:04 AM
for almost 50 different companies I have to use it eg:#google=google,#yahoo=yahoo and so on
Created 12-27-2016 12:46 PM
Its working properly I have applied this logic
if (readConfiguration.getInstance() .getPropertyMap() .containsKey(word.replace("#", ""))) { String companyName = readConfiguration .getPropertyMap().get( word.replace("#", ""));
Thanks.
Created 12-27-2016 12:48 PM
if (readConfiguration.getInstance() .getPropertyMap() .containsKey(word.replace("#", ""))) { String companyName = readConfiguration .getPropertyMap().get( word.replace("#", ""));
This logic is been implemented and getting the desired output.
Thanks.