Java Code Examples for org.apache.hadoop.conf.Configuration#onlyKeyExists()

The following examples show how to use org.apache.hadoop.conf.Configuration#onlyKeyExists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestConfigurationFieldsBase.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
  * Pull properties and values from filename.
  *
  * @param filename XML filename
  * @return HashMap containing <Property,Value> entries from XML file
  */
 private HashMap<String,String> extractPropertiesFromXml
     (String filename) {
   if (filename==null) {
     return null;
   }

   // Iterate through XML file for name/value pairs
   Configuration conf = new Configuration(false);
   conf.setAllowNullValueProperties(true);
   conf.addResource(filename);

   HashMap<String,String> retVal = new HashMap<String,String>();
   Iterator<Map.Entry<String,String>> kvItr = conf.iterator();
   while (kvItr.hasNext()) {
     Map.Entry<String,String> entry = kvItr.next();
     String key = entry.getKey();
     // Ignore known xml props
     if (xmlPropsToSkipCompare != null) {
       if (xmlPropsToSkipCompare.contains(key)) {
         continue;
       }
     }
     // Ignore known xml prefixes
     boolean skipPrefix = false;
     if (xmlPrefixToSkipCompare != null) {
       for (String xmlPrefix : xmlPrefixToSkipCompare) {
  if (key.startsWith(xmlPrefix)) {
    skipPrefix = true;
           break;
  }
}
     }
     if (skipPrefix) {
       continue;
     }
     if (conf.onlyKeyExists(key)) {
       retVal.put(key,null);
     } else {
       String value = conf.get(key);
       if (value!=null) {
         retVal.put(key,entry.getValue());
       }
     }
     kvItr.remove();
   }
   return retVal;
 }
 
Example 2
Source File: TestConfigurationFieldsBase.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
  * Pull properties and values from filename.
  *
  * @param filename XML filename
  * @return HashMap containing <Property,Value> entries from XML file
  */
 private HashMap<String,String> extractPropertiesFromXml
     (String filename) {
   if (filename==null) {
     return null;
   }

   // Iterate through XML file for name/value pairs
   Configuration conf = new Configuration(false);
   conf.setAllowNullValueProperties(true);
   conf.addResource(filename);

   HashMap<String,String> retVal = new HashMap<String,String>();
   Iterator<Map.Entry<String,String>> kvItr = conf.iterator();
   while (kvItr.hasNext()) {
     Map.Entry<String,String> entry = kvItr.next();
     String key = entry.getKey();
     // Ignore known xml props
     if (xmlPropsToSkipCompare != null) {
       if (xmlPropsToSkipCompare.contains(key)) {
         continue;
       }
     }
     // Ignore known xml prefixes
     boolean skipPrefix = false;
     if (xmlPrefixToSkipCompare != null) {
       for (String xmlPrefix : xmlPrefixToSkipCompare) {
  if (key.startsWith(xmlPrefix)) {
    skipPrefix = true;
           break;
  }
}
     }
     if (skipPrefix) {
       continue;
     }
     if (conf.onlyKeyExists(key)) {
       retVal.put(key,null);
     } else {
       String value = conf.get(key);
       if (value!=null) {
         retVal.put(key,entry.getValue());
       }
     }
     kvItr.remove();
   }
   return retVal;
 }