List of usage examples for org.apache.commons.io IOUtils toString
public static String toString(byte[] input, String encoding) throws IOException
byte[]
as a String using the specified character encoding. From source file:com.gooddata.util.ResourceUtils.java
public static String readStringFromResource(String resourcePath) { try {/* ww w. j a v a 2s .co m*/ return IOUtils.toString(readFromResource(resourcePath), StandardCharsets.UTF_8); } catch (IOException e) { throw new IllegalStateException(format("Cannot read from resource %s", resourcePath), e); } }
From source file:com.opentable.etcd.EtcdServerRule.java
private static String newDiscoveryUrl(int clusterSize) { try {// www .j a v a 2 s. c o m return IOUtils.toString(new URL("https://discovery.etcd.io/new?size=" + clusterSize), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.adguard.compiler.UrlUtils.java
public static String downloadString(URL url, String encoding) throws IOException { HttpURLConnection connection = null; InputStream inputStream = null; try {/*from w w w . j a v a 2 s.c o m*/ connection = (HttpURLConnection) url.openConnection(); connection.connect(); inputStream = connection.getInputStream(); return IOUtils.toString(inputStream, encoding); } finally { IOUtils.closeQuietly(inputStream); if (connection != null) { connection.disconnect(); } } }
From source file:de.tobiasbruns.content.storage.TestUtils.java
public static String loadTextFile(String filename) { try {/*w w w .j a v a 2 s . c om*/ return IOUtils.toString(loadFile(filename), "UTF-8"); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:costumetrade.common.http.HttpClientUtilsWrapper.java
public static HttpResponse doPost(HttpMessage message) throws UnsupportedOperationException, IOException { logger.info("?{}....", message.getUrl()); try (CloseableHttpClient httpclient = HttpClients.custom().build();) { HttpPost request = new HttpPost(message.getUrl()); request.setEntity(message.getHttpEntity()); try (CloseableHttpResponse response = httpclient.execute(request);) { int statusCode = response.getStatusLine().getStatusCode(); logger.info("?{}???{}", message.getUrl(), statusCode); if (HttpStatus.SC_OK == statusCode) { String result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name()); logger.info("?:{}", result); return new HttpResponse(statusCode, result, message.getCallbackData()); }/* w w w . ja v a 2 s . co m*/ return new HttpResponse(statusCode, null, message.getCallbackData()); } } }
From source file:com.hp.ov.sdk.dto.ExtraStorageVolumeTest.java
@BeforeClass public static void setupTest() throws IOException { Class<ExtraStorageVolumeTest> clazz = ExtraStorageVolumeTest.class; extraAccessList = IOUtils.toString(clazz.getResourceAsStream("ExtraAccessList.json"), "UTF-8"); }
From source file:com.gooddata.dataset.MaqlDmlTest.java
@Test public void testSerialization() throws Exception { final String json = IOUtils.toString(getClass().getResourceAsStream("/dataset/maqlDml.json"), "UTF-8"); assertThat(new ObjectMapper().writeValueAsString(new MaqlDml("maqlddl")), is(json)); }
From source file:com.reprezen.kaizen.oasparser.jsonoverlay.JsonLoader.java
public static JsonNode load(URL url) throws IOException { String urlString = url.toString(); if (cache.containsKey(urlString)) { return cache.get(urlString); }// w ww .ja va 2 s. c o m String json = IOUtils.toString(url.openStream(), Charsets.UTF_8); return loadString(url, json); }
From source file:myproject.Model.Common.ProcessExecutor.java
private static String properExecute(File file, String... commands) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(commands); if (file != null) { builder.directory(file);/* w ww .jav a 2s . c om*/ } Process process = builder.start(); String input = IOUtils.toString(process.getInputStream(), "utf-8"); String error = IOUtils.toString(process.getErrorStream(), "utf-8"); //String command = Arrays.toString(builder.command().toArray(new String[] {})); process.waitFor(); process.getInputStream().close(); if (!error.isEmpty()) { Log.errorLog(error, ProcessExecutor.class); } String result = input; if (input.isEmpty()) { result = error; } return result; }
From source file:com.ixortalk.aws.cognito.boot.filter.util.FileUtil.java
public static String fileContent(final String dirPrefix, final String fileName) { String name = null;// ww w. jav a 2s.co m try { name = dirPrefix + "/" + fileName; return IOUtils.toString(FileUtil.class.getClassLoader().getResourceAsStream(name), UTF_8); } catch (Exception e) { throw new RuntimeException("Error reading file " + name + ": " + e.getMessage(), e); } }