List of usage examples for org.apache.commons.io IOUtils toString
public static String toString(byte[] input) throws IOException
byte[]
as a String using the default character encoding of the platform. From source file:com.commsen.jwebthumb.test.JWebThumbRequestsTest.java
@BeforeClass public static void setApikey() throws IOException { apikey = IOUtils.toString(ClassLoader.getSystemClassLoader().getResourceAsStream("apikey.txt")); webThumbService = new WebThumbService(apikey); }
From source file:com.anto89.processor.ProcessorManager.java
public boolean run(String urlString) { JSONArray json = null;//from ww w . j a v a 2 s. c o m try { URL url = new URL(urlString); String jsonResult = IOUtils.toString(url); json = (JSONArray) JSONValue.parseWithException(jsonResult); } catch (MalformedURLException ex) { Logger.getLogger(ProcessorManager.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (IOException | ParseException ex) { Logger.getLogger(ProcessorManager.class.getName()).log(Level.SEVERE, null, ex); return false; } // data valid only if (json == null || json.isEmpty()) { return false; } // setup result result.put("url_data", urlString); result.put("process_time", new Date()); for (Processor p : list) { p.setReturnJson(result); } // main processing for (int i = 0; i < json.size(); i++) { JSONObject data = (JSONObject) json.get(i); for (Processor p : list) { p.run(data); } } // return result for (Processor p : list) { p.getReturnJson(); } return true; }
From source file:io.sidecar.query.HistogramAnswerValidationTest.java
@BeforeMethod public void loadValidEventJsonAsString() throws Exception { validHistogramAsJsonString = IOUtils .toString(this.getClass().getResource("/proposed_histogram_answer.json")); }
From source file:io.sidecar.query.StatsAnswerJsonValidationTest.java
@BeforeMethod public void loadValidEventJsonAsString() throws Exception { validStatsAnswerAsJsonString = IOUtils.toString(this.getClass().getResource("/proposed_stats_answer.json")); }
From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java
public static void createGraph(String name, String outputDir, IGraph graph, String htmlData) throws IOException { LOGGER.info("Creating graph " + name + "...."); String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/graph-curved.html")); content = content.replaceAll(Pattern.quote("$CSVNAME$"), Matcher.quoteReplacement(name)) .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData)); FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content); File file = new File(outputDir + File.separator + name + ".csv"); writeGraph(file, graph);/*from w w w .j a v a2s.c o m*/ TpaPersistorUtils.copyFromResourceToDir("d3.v3.js", outputDir); LOGGER.info("... created graph " + name + "."); }
From source file:com.manisha.allmybooksarepacked.service.BookParser.java
public BookParser(String filePath) throws IOException { URL url = BookParser.class.getClassLoader().getResource(filePath); //System.out.println(url.getPath()); htmlContent = IOUtils.toString(url); doc = Jsoup.parse(htmlContent);//from ww w .j av a 2s.c o m book = parseBookValues(); }
From source file:com.ctrip.infosec.rule.executor.RulesExecutorServiceTest.java
@Test @Ignore/* w w w . j a v a 2 s . com*/ public void testRules() throws IOException { String jsonData = IOUtils.toString(new DefaultResourceLoader().getResource("/1_1.txt").getInputStream()); RiskFact fact = JSON.parseObject(jsonData, RiskFact.class); rulesExecutorService.executeSerial(fact); jsonData = IOUtils.toString(new DefaultResourceLoader().getResource("/1.txt").getInputStream()); fact = JSON.parseObject(jsonData, RiskFact.class); rulesExecutorService.executeSyncRules(fact); System.out.println(JSON.toJSONString(fact)); }
From source file:com.switchfly.inputvalidation.sanitizer.StripHtmlSanitizerTest.java
@Test public void testExecute() throws Exception { StripHtmlSanitizer sanitizer = new StripHtmlSanitizer(); String html = IOUtils.toString(getClass().getResourceAsStream("StripHtmlSanitizerTest_dirty.html")); assertEquals("SPG Flights FAQs Home Frequently Asked Questions", sanitizer.execute(html)); }
From source file:com.yonisamlan.android.metaqr.AttributionsActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textView = new TextView(this); setContentView(textView);//from ww w . ja v a2 s. c o m String html; try { html = IOUtils.toString(getResources().openRawResource(R.raw.licenses)); } catch (NotFoundException e) { e.printStackTrace(); html = "Error reading license."; } catch (IOException e) { e.printStackTrace(); html = "Error reading license."; } textView.setText(Html.fromHtml(html)); textView.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:net.hillsdon.reviki.webtests.TestAttachments.java
public static String getAttachmentAtEndOfLink(final HtmlAnchor link) throws IOException { UnexpectedPage attachment = (UnexpectedPage) link.click(); BufferedReader in = new BufferedReader(new InputStreamReader(attachment.getInputStream())); try {/*w w w.jav a 2 s. c om*/ return IOUtils.toString(in).trim(); } finally { in.close(); } }