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:ch.ralscha.extdirectspring.generator.GeneratorTestUtil.java
public static void compareExtJs4Code(String model, String value, boolean debug, boolean apiWithQuotes) { try {/*from ww w . j av a2 s.c o m*/ String expectedValue = IOUtils.toString(GeneratorTestUtil.class .getResourceAsStream("/generator/" + model + "ExtJs4" + (apiWithQuotes ? "Q" : "") + ".json")); compareModelString(expectedValue, value, debug); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:deployer.publishers.openshift.inject.ExtraFilesInjectorTest.java
private static void assertArtifactResource(ArtifactResource resource, String path) throws IOException { Assert.assertNull(resource.getPermissions()); // Check actual contents String expected = IOUtils.toString(ExtraFilesInjectorTest.class.getResourceAsStream( ("/" + ExtraFilesInjector.EXTRA_FILES_CLASSPATH + path).replaceAll("\\.", "/"))); String received = IOUtils.toString(resource.getStream()); Assert.assertEquals(expected, received); }
From source file:me.ryandowling.Utils.java
public static String urlToString(String url) throws IOException { InputStream in = new URL(url).openStream(); String response = null;// w ww . ja v a 2 s . c o m try { response = IOUtils.toString(in); } finally { IOUtils.closeQuietly(in); } return response; }
From source file:com.intel.cosbench.api.mock.MockUtils.java
public static String toString(InputStream data) { String string = null;//from w w w.java 2 s.co m try { string = IOUtils.toString(data); } catch (IOException ioe) { // will not happen } return string; }
From source file:com.canoo.webtest.util.FileUtil.java
/** * Reads a file into a String./*from w w w .j a v a 2 s .c om*/ * * @param file * @param step * @return the resulting String */ public static String readFileToString(final File file, final Step step) { String canonicalPath = null; String result = null; InputStream inputStream = null; try { canonicalPath = file.getCanonicalPath(); inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); } catch (IOException e) { throw new StepExecutionException("Could not find/read \"" + canonicalPath + "\".", step); } finally { IOUtils.closeQuietly(inputStream); } return result; }
From source file:net.es.nsi.pce.util.ContentType.java
public static String decode2String(String contentType, InputStream is) throws IOException { if (XGZIP.equalsIgnoreCase(contentType)) { return IOUtils.toString(new GZIPInputStream(is)); } else {/*from w w w .j a va2 s . co m*/ return IOUtils.toString(is); } }
From source file:com.aestasit.markdown.BaseTest.java
protected static InputStream allTestData() throws IOException { ByteArrayOutputStream data = new ByteArrayOutputStream(); for (String fileName : allTestFiles()) { IOUtils.write(IOUtils.toString(testData(fileName)), data); }/*from w ww. jav a2 s . c om*/ IOUtils.closeQuietly(data); return new ByteArrayInputStream(data.toByteArray()); }
From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java
public static void createGraph(String name, String outputDir, GraphCSV csv, String htmlData) throws IOException { 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); FileUtils.writeStringToFile(new File(outputDir + File.separator + name + ".csv"), csv.toString()); TpaPersistorUtils.copyFromResourceToDir("d3.v3.js", outputDir); }
From source file:cd.go.authentication.ldap.utils.Util.java
public static String readResource(String resourceFile) { try (InputStreamReader reader = new InputStreamReader(Util.class.getResourceAsStream(resourceFile), StandardCharsets.UTF_8)) { return IOUtils.toString(reader); } catch (IOException e) { throw new RuntimeException("Could not find resource " + resourceFile, e); }// w w w . j a va 2s. c o m }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.CompressionUtilsTest.java
private static void testCompression(CompressionMethod compressionMethod) throws IOException { String text = StringUtils.repeat("This is a test. ", 100000); File file = new File("compressed" + compressionMethod.getExtension()); OutputStream os = CompressionUtils.getOutputStream(file); os.write(text.getBytes());/*from w ww . j a va 2 s .c o m*/ os.close(); InputStream is = CompressionUtils.getInputStream(file.getPath(), new FileInputStream(file)); assertEquals(text, IOUtils.toString(is)); is.close(); file.delete(); }