Advertisement
aironman

how to use a properties file

Jan 2nd, 2015
214
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static boolean processProperties(String absPropertiesPath) throws IOException {
  2.  
  3. LOGGER.debug("Started with properties " + absPropertiesPath);
  4. boolean isOk = false;
  5. Properties prop = new Properties();
  6. InputStream input = null;
  7.  
  8. //maybe some day we need to provide an internal properties file. this is how to do it!
  9. // processing internal properties file
  10. // String filename = "feed-adaptor.properties";
  11.  
  12. // input =
  13. // Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
  14. // prop.load(input);
  15.  
  16. String filename = absPropertiesPath;
  17. LOGGER.debug("trying to open properties file: " + filename);
  18. input = new FileInputStream(filename);
  19. prop.load(input);
  20.  
  21. if (prop.isEmpty()) {
  22. LOGGER.fatal("ATENTION! the properties file " + filename + " is empty. Aborting!");
  23. return isOk;
  24. }
  25. // where are the datacast files? it could come many of them!
  26. DATACAST_PATH = prop.getProperty("data_cast_path");
  27. C2D_AGGR_DR_HDFS_PATH = prop.getProperty("c2d_aggr_dr_hdfs_path");
  28. DISCARDED_HDSF_PATH = prop.getProperty("discarded_hdfs_path");
  29. CSV_MAPPING = prop.getProperty("csv_mapping");
  30. DUPLICATE_LAST_COLUMN = prop.getProperty("duplicateLastColumn");
  31. FILENAME_REGEX = prop.getProperty("filenameregex");
  32. SERVICE_ID = prop.getProperty("service_id");
  33. DEFAULTFS = prop.getProperty("fs.defaultFS");
  34.  
  35. // true everythings ok
  36. if ((DATACAST_PATH != null) && (!("").equals(DATACAST_PATH)) && (C2D_AGGR_DR_HDFS_PATH != null)
  37. && (!("").equals(C2D_AGGR_DR_HDFS_PATH)) && (DISCARDED_HDSF_PATH != null)
  38. && (!("").equals(DISCARDED_HDSF_PATH)) && (CSV_MAPPING != null) && (!("").equals(CSV_MAPPING))
  39. && (DUPLICATE_LAST_COLUMN != null) && (!("").equals(DUPLICATE_LAST_COLUMN)) && (FILENAME_REGEX != null)
  40. && (!("").equals(FILENAME_REGEX)) && (SERVICE_ID != null) && (!("").equals(SERVICE_ID))
  41. && (DEFAULTFS != null) && (!("").equals(DEFAULTFS))) {
  42.  
  43. isOk = true;
  44. LOGGER.debug("DATACAST_PATH, C2D_AGGR_DR_HDFS_PATH, DISCARDED_HDSF_PATH, CSV_MAPPING, DUPLICATE_LAST_COLUMN, FILENAME_REGEX, SERVICE_ID looks find. "
  45. + DATACAST_PATH
  46. + " "
  47. + C2D_AGGR_DR_HDFS_PATH
  48. + " "
  49. + DISCARDED_HDSF_PATH
  50. + " "
  51. + CSV_MAPPING
  52. + " "
  53. + DUPLICATE_LAST_COLUMN + " " + FILENAME_REGEX + " " + SERVICE_ID + " DEFAULTFS: " + DEFAULTFS);
  54. }
  55.  
  56. if (input != null) {
  57. input.close();
  58. }
  59. return isOk;
  60. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement