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.teradata.presto.yarn.test.slider.SliderStatusTest.java
@Test public void testSliderStatus() throws IOException { String statusJson = IOUtils.toString(getClass().getResourceAsStream("/status_file")); SliderStatus sliderStatus = new SliderStatus(statusJson); assertThat(sliderStatus.getLiveComponentsHost("UNKNOWN")).isEmpty(); assertThat(sliderStatus.getLiveContainers("UNKNOWN")).isEqualTo(0); assertThat(sliderStatus.getLiveContainers("COORDINATOR")).isEqualTo(1); assertThat(sliderStatus.getLiveComponentsHost("COORDINATOR")) .containsExactly("kogut-vsphere-default-master"); assertThat(sliderStatus.getLiveComponentsHost("WORKER")).containsExactly("kogut-vsphere-default-slave2", "kogut-vsphere-default-slave1", "kogut-vsphere-default-slave3"); assertThat(sliderStatus.getLiveContainers("WORKER")).isEqualTo(3); }
From source file:com.ecofactor.qa.automation.util.HttpUtil.java
/** * Gets the./*from w w w . j av a 2 s . c o m*/ * @param url the url * @return the http response */ public static String get(String url, Map<String, String> params, int expectedStatus) { String content = null; HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); URIBuilder builder = new URIBuilder(request.getURI()); Set<String> keys = params.keySet(); for (String key : keys) { builder.addParameter(key, params.get(key)); } HttpResponse response = null; try { request.setURI(builder.build()); DriverConfig.setLogString("URL " + request.getURI().toString(), true); response = httpClient.execute(request); content = IOUtils.toString(response.getEntity().getContent()); DriverConfig.setLogString("Content " + content, true); Assert.assertEquals(response.getStatusLine().getStatusCode(), expectedStatus); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { request.releaseConnection(); } return content; }
From source file:com.github.ctrimble.chlorine.asm.examples.SimpleURLLoaderBefore.java
public String loadUrl(String spec) throws Exception { return IOUtils.toString(new URL(spec)); }
From source file:com.prodyna.liferay.devcon.hystrix.demo.service.ChuckNorrisFactsServiceClient.java
/** * Call Chuck Norris facts service using simple {@link HttpURLConnection}. * /*from ww w . j a v a 2 s .co m*/ * @return Fact about Chuck Norris. * @throws IOException * is thrown if the service could not be called for some reason. */ public static String callChuckNorrisFactsService() throws IOException { URL url = new URL(CHUCK_NORRIS_SERVICE_ENDPOINT); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream inputStream = connection.getInputStream(); String response = IOUtils.toString(inputStream); JSONObject jsonResponse = new JSONObject(response); String chuckNorrisFact = jsonResponse.getString("fact"); return chuckNorrisFact; }
From source file:com.nextdoor.bender.operations.json.OperationTest.java
protected String getResourceString(String resource) throws UnsupportedEncodingException, IOException { return IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream(resource), "UTF-8")); }
From source file:com.google.code.docbook4j.XSLTUtils.java
public static final String dumpCss(String baseDir, String location) { try {/* w w w . j a v a 2 s . co m*/ FileObject fo = FileObjectUtils.resolveFile(location, baseDir); StringBuffer sb = new StringBuffer(); sb.append("<!--\n"); sb.append(IOUtils.toString(fo.getContent().getInputStream())).append("\n"); sb.append("-->\n"); fo.close(); return sb.toString(); } catch (Exception e) { log.error("Error reading css file: " + location, e); } return ""; }
From source file:com.github.ctrimble.neon.asm.examples.SimpleURLLoaderAfter.java
public String loadUrl(String spec) throws Exception { return IOUtils.toString(com.github.ctrimble.neon.URLFactory.newURL(spec)); }
From source file:com.github.ctrimble.chlorine.asm.examples.SimpleURLLoaderAfter.java
public String loadUrl(String spec) throws Exception { return IOUtils.toString(com.github.ctrimble.chlorine.URLFactory.newURL(spec)); }
From source file:io.cloudslang.lang.cli.SlangBannerTest.java
@Test public void testGetBanner() throws Exception { String banner = IOUtils.toString(getClass().getResource("/slangBanner1.txt").toURI()); Assert.assertTrue(slangBanner.getBanner().contains(banner)); }
From source file:com.github.lucasvc.LabelNotVisibleTest.java
@Test public void versus() throws Exception { WebClient client = new WebClient(); String a = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("p.html")); StringWebResponse response = new StringWebResponse(a, new URL("https://any.to/")); HtmlPage page = HTMLParser.parseHtml(response, client.getCurrentWindow()); DomNode label = page.getElementsByTagName("label").get(0); Assert.assertTrue(label.isDisplayed()); }