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.flipkart.zjsonpatch.PatchTestCase.java
public static Collection<PatchTestCase> load(String fileName) throws IOException { String path = "/testdata/" + fileName + ".json"; InputStream resourceAsStream = PatchTestCase.class.getResourceAsStream(path); String testData = IOUtils.toString(resourceAsStream, "UTF-8"); JsonNode tree = MAPPER.readTree(testData); List<PatchTestCase> result = new ArrayList<PatchTestCase>(); for (JsonNode node : tree.get("errors")) { if (isEnabled(node)) { result.add(new PatchTestCase(false, node)); }/*w w w . j a v a 2 s.com*/ } for (JsonNode node : tree.get("ops")) { if (isEnabled(node)) { result.add(new PatchTestCase(true, node)); } } return result; }
From source file:fr.pilato.elasticsearch.tools.SettingsReader.java
/** * Read a file content from the classpath * @param file filename/* w w w . j a v a2 s.c om*/ */ public static String readFileFromClasspath(String file) { logger.trace("Reading file [{}]...", file); String content = null; try (InputStream asStream = SettingsReader.class.getClassLoader().getResourceAsStream(file)) { if (asStream == null) { logger.trace("Can not find [{}] in class loader.", file); return null; } content = IOUtils.toString(asStream, "UTF-8"); } catch (IOException e) { logger.warn("Can not read [{}].", file); } return content; }
From source file:net.jadler.matchers.BodyRequestMatcher.java
@Override protected String retrieveValue(final Request req) throws Exception { return IOUtils.toString(req.getBody(), req.getEncoding()); }
From source file:it.VerifyIT.java
private void ensureMatch(String file) throws Exception { String sourcePath = "case-01/" + file; InputStream sourceInput = VerifyIT.class.getClassLoader().getResourceAsStream(sourcePath); String sourceText = IOUtils.toString(sourceInput, "UTF-8"); System.out.println("source\n" + sourceText); String targetPath = "OSGI-INF/service-component/" + file; InputStream targetInput = VerifyIT.class.getClassLoader().getResourceAsStream(targetPath); String targetText = IOUtils.toString(targetInput, "UTF-8"); System.out.println("target\n" + targetText); assertEquals(sourceText, targetText); }
From source file:com.amitinside.java8.concurrency.CompletableFutureInAction.java
private static String downloadSite(final String site) { try {/* w w w . ja va2 s. c o m*/ logger.debug("Downloading {}", site); final String res = IOUtils.toString(new URL("http://" + site).openStream(), "UTF-8"); logger.debug("Done {}", site); return res; } catch (final IOException e) { throw Throwables.propagate(e); } }
From source file:com.synopsys.integration.util.ResourceUtil.java
public static String getResourceAsString(final Class<?> clazz, final String resourceName, final Charset encoding) throws IOException { final InputStream inputStream = clazz.getResourceAsStream(resourceName); if (inputStream != null) { return IOUtils.toString(inputStream, encoding); }//from w ww .ja va2 s . c om return null; }
From source file:headhunt.fx.setup.views.license.LicensePresenter.java
@Override public void initialize(URL url, ResourceBundle rb) { System.out.println("LicenseCtrl.initialize()"); try {// w w w. java 2s. c o m String lic = IOUtils.toString(this.getClass().getResourceAsStream("/data/license-gpl-3.0.txt"), "UTF-8"); license.setText(lic); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.github.restdriver.serverdriver.file.FileHelper.java
/** * Reads in a resource from the class path. * /* w w w. j a va2s . c om*/ * @param fileName The file name to load * @param encoding The encoding to use when reading the file * @return The content of the file */ public static String fromFile(String fileName, String encoding) { InputStream stream = FileHelper.class.getClassLoader().getResourceAsStream(fileName); if (stream == null) { throw new RuntimeFileNotFoundException(new FileNotFoundException(fileName)); } try { return IOUtils.toString(stream, encoding); } catch (IOException e) { throw new RuntimeException("Failed to read from file " + fileName, e); } }
From source file:de.shadowhunt.subversion.internal.ResourcePropertyUtils.java
static InputStream escapedInputStream(final InputStream inputStream) throws IOException { final String rawData = IOUtils.toString(inputStream, UTF8); inputStream.close();/*from ww w . jav a 2s. c o m*/ final Matcher matcher = PATTERN.matcher(rawData); final String escapedData = matcher.replaceAll("<$1$2$3:$4" + MARKER + "$5$6$7>"); return IOUtils.toInputStream(escapedData, UTF8); }
From source file:com.yahoo.yqlplus.example.apis.WeatherProgramTest.java
@Test public void testWeatherSource() throws Exception { Injector injector = Guice.createInjector(new SourceModule()); YQLPlusCompiler compiler = injector.getInstance(YQLPlusCompiler.class); String programStr = IOUtils.toString(this.getClass().getResourceAsStream("/programs/weather.program"), "UTF-8"); CompiledProgram program = compiler.compile(programStr); Object result = program.run(ImmutableMap.<String, Object>of("text", "sfo"), false).getResult("weather") .get().getResult();//from w w w .ja v a 2 s. c o m System.out.println("result " + result); }