/** * Use the resource location to read the String contents. * @param location * @return String | null if resource is not available */ @SuppressWarnings("PMD.EmptyCatchBlock") private static String contentOrNull(String location) { if (location.startsWith("http://")) { return fetchContentOrNull(location); } String content = null; InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(location); if (is == null) { // retry different loader is = StringResource.class.getResourceAsStream(location); } if (is != null) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder builder = new StringBuilder(256); while (reader.ready()) builder.append(reader.readLine()).append('\n'); content = builder.toString(); } catch (IOException e) { Logger.getAnonymousLogger().log(Level.WARNING, "Unable to fetch content from:"+ location); // eat it, content stays null } } return content; }