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; }
/** * 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 }
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; } } }