private List<String> getTopicTweets(HttpServletRequest request) throws ServletException {

    final String topicFile = request.getParameter("topicFile");
    final String fullFilePath = topicFile;
    List<String> listFiles = new ArrayList<String>();

    Properties properties = new Properties();

    try {
      properties.load(new FileInputStream(fullFilePath));
    } catch (FileNotFoundException e) {
      LOGGER.error("missing file for in topic tweets: '" + fullFilePath + "'" + e.getMessage());
      e.printStackTrace();
    } catch (IOException e) {
      LOGGER.error("can't read file for in topic tweets: '" + fullFilePath + "'" + e.getMessage());
      e.printStackTrace();
    }

    for (Entry<Object, Object> propertyEntry : properties.entrySet()) {
      String key = (String) propertyEntry.getKey();
      if (key.startsWith("inTopic")) {
        listFiles.add((String) propertyEntry.getValue());
      }
    }

    List<String> tweets = new ArrayList<String>();
    for (String filtFile : listFiles) {
      tweets.addAll(parseTweetsFromFile(filtFile));
    }
    return tweets;
  }
  private List<String> getOutOfTopicTweets(HttpServletRequest request) throws ServletException {

    String topicFile = request.getParameter("topicFile");

    List<String> listFiles = new ArrayList<String>();
    Properties properties = new Properties();
    try {
      properties.load(new FileInputStream(topicFile));
    } catch (FileNotFoundException e) {
      final String emsg =
          "missing file for out of topic tweets: '" + topicFile + "'" + e.getMessage();
      LOGGER.error(emsg);
      throw new ServletException(emsg, e);
    } catch (IOException e) {
      final String emsg =
          "can't read file for out of topic tweets: '" + topicFile + "'" + e.getMessage();
      LOGGER.error(emsg);
      throw new ServletException(emsg);
    }

    for (Entry<Object, Object> propertyEntry : properties.entrySet()) {
      String key = (String) propertyEntry.getKey();

      if (key.startsWith("outOfTopic")) {
        listFiles.add((String) propertyEntry.getValue());
      }
    }

    List<String> tweets = new ArrayList<String>();
    for (String filtFile : listFiles) {
      tweets.addAll(parseTweetsFromFile(filtFile));
    }
    return tweets;
  }
 /**
  * Get the configurations from the configurations File as a {@link JsonElement}
  *
  * @return {@link JsonElement} The configuration tree contained inside the configuration File. If
  *     the File doesn't exist or an error occurred, the default configuration tree is returned
  */
 private JsonElement getConfigurationTreeFromFile() {
   if (mConfigurationFile.exists()) { // Check, if the configuration File exists on disk
     JsonParser parser = new JsonParser();
     try {
       JsonElement result = parser.parse(new FileReader(mConfigurationFile));
       if (result.isJsonObject()) { // Check if content is a valid JsonObject
         return result;
       }
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     }
   }
   return mDefaultConfigurations; // If the configurations File doesn't exist on disk, return the
                                  // default configurations
 }
示例#4
0
 private CIJob getJob(ApplicationInfo appInfo) throws PhrescoException {
   Gson gson = new Gson();
   try {
     BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo)));
     CIJob job = gson.fromJson(br, CIJob.class);
     br.close();
     return job;
   } catch (FileNotFoundException e) {
     S_LOGGER.debug(e.getLocalizedMessage());
     return null;
   } catch (com.google.gson.JsonParseException e) {
     S_LOGGER.debug("it is already adpted project !!!!! " + e.getLocalizedMessage());
     return null;
   } catch (IOException e) {
     S_LOGGER.debug(e.getLocalizedMessage());
     return null;
   }
 }
示例#5
0
  public JSONProperties load(String basePath) {
    if (classLoader != null) {
      InputStream in = classLoader.getResourceAsStream(basePath);

      if (in != null) {
        load0(new InputStreamReader(in));
      } else {
        throw new NullPointerException("classLoader.getResourceAsStream() is null!");
      }

      return this;
    } else {
      try {
        load0(new FileReader(basePath));

        return this;
      } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
      }
    }
  }