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.esofthead.mycollab.core.utils.FileUtils.java
public static String readFileAsPlainString(String fileName) { try {/*from w w w. j a va 2 s . c om*/ File pricingFile = FileUtils.getDesireFile(FileUtils.getUserFolder(), fileName, "src/main/conf/" + fileName); InputStream pricingStream; if (pricingFile != null) { pricingStream = new FileInputStream(pricingFile); } else { pricingStream = FileUtils.class.getClassLoader().getResourceAsStream(fileName); } return IOUtils.toString(pricingStream, "UTF-8"); } catch (IOException e) { throw new MyCollabException(e); } }
From source file:demo.server.FlowServiceImpl.java
@Override public String getMainFlow() { final InputStream flowFileStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("/Main.flow"); if (flowFileStream == null) { return null; } else {//from w w w. j a va 2 s. co m try { return IOUtils.toString(flowFileStream, "UTF-8"); } catch (final IOException e) { return null; } finally { IOUtils.closeQuietly(flowFileStream); } } }
From source file:cz.klajmajk.camunda.varna.DiagramBean.java
public String getProcessDiagram() throws IOException { InputStream is = rs.getProcessModel(pi.getProcessDefinitionId()); return IOUtils.toString(is, "UTF-8").replaceAll("\\$\\{.*?\\}", ""); }
From source file:league.stat.checker.nameToID.java
public String nameToID(String name) throws IOException { //HTTP response input code taken WhiteFang34 on Stack overflow ; http://stackoverflow.com/questions/5769717/how-can-i-get-an-http-response-body-as-a-string-in-java URL url = new URL("https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/" + name + "?api_key=RGAPI-f2ba678c-7c42-4265-8c36-ae1364c3e9b9"); URLConnection con = url.openConnection(); InputStream in = con.getInputStream(); String encoding = con.getContentEncoding(); encoding = encoding == null ? "UTF-8" : encoding; String body = IOUtils.toString(in, encoding); //Make this code more efficient by using String slicing int index = body.indexOf("id") + 4; String sID = ""; while (body.charAt(index) != ',') { sID += body.charAt(index);/*from w ww . ja va2 s. c o m*/ index++; } return sID; }
From source file:io.wcm.maven.plugins.i18n.readers.JsonI18nReader.java
@Override public Map<String, String> read(File sourceFile) throws IOException { String fileContent = IOUtils.toString(sourceFile.toURI().toURL(), CharEncoding.UTF_8); try {//from w w w .ja va 2 s .co m JSONObject root = new JSONObject(fileContent); Map<String, String> map = new HashMap<String, String>(); parseJson(root, map, ""); return map; } catch (JSONException ex) { throw new IOException("Unable to read JSON from " + sourceFile.getAbsolutePath(), ex); } }
From source file:com.blackducksoftware.integration.hub.detect.detector.go.GopkgLockParserTest.java
@Test public void gopkgParserTest() throws IOException { final GopkgLockParser gopkgLockParser = new GopkgLockParser(new ExternalIdFactory()); final String gopkgLockContents = IOUtils.toString(getClass().getResourceAsStream("/go/Gopkg.lock"), StandardCharsets.UTF_8); final DependencyGraph dependencyGraph = gopkgLockParser.parseDepLock(gopkgLockContents); Assert.assertNotNull(dependencyGraph); DependencyGraphResourceTestUtil.assertGraph("/go/Go_GopkgExpected_graph.json", dependencyGraph); }
From source file:com.thinkbiganalytics.feedmgr.rest.model.FeedMetadataJsonTest.java
@Test public void deserializationSortedTest() throws Exception { Resource r = new ClassPathResource("sorted-feed.json"); String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); FeedMetadata feed = ObjectMapperSerializer.deserialize(json, FeedMetadata.class); assertNotNull(feed);/*w ww .j a v a 2s . com*/ }
From source file:com.brainlounge.zooterrain.netty.WebSocketServerIndexPage.java
public WebSocketServerIndexPage() throws IOException { final InputStream resourceAsStream = WebSocketServerIndexPage.class.getResourceAsStream("/index.html"); content = IOUtils.toString(resourceAsStream, "UTF-8"); }
From source file:io.selendroid.server.util.HttpClientUtil.java
public static JSONObject parseJsonResponse(HttpResponse response) throws Exception { String r = IOUtils.toString(response.getEntity().getContent(), "UTF-8"); try {/*w w w . j a v a 2 s.com*/ return new JSONObject(r); } catch (JSONException e) { log.severe("Failed to parse json response: " + r); throw e; } }
From source file:com.thoughtworks.go.server.JettyCustomErrorPageHandler.java
public JettyCustomErrorPageHandler() throws IOException { try (InputStream in = getClass().getResourceAsStream("/error.html")) { fileContents = IOUtils.toString(in, StandardCharsets.UTF_8); }/*from ww w. jav a 2 s.c om*/ }