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.netflix.spinnaker.halyard.backup.kms.v1.SecureStorage.java
public void backupFile(String name, File file) { String contents;//from w w w . j ava 2 s .c om try { contents = IOUtils.toString(new FileInputStream(file)); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Can't load file for secure storage: " + e.getMessage(), e); } storeContents(name, contents); }
From source file:com.alibaba.jstorm.utils.SystemOperation.java
public static String exec(String cmd) throws IOException { LOG.debug("Shell cmd: " + cmd); Process process = new ProcessBuilder(new String[] { "/bin/bash", "-c", cmd }).start(); try {/* w w w . j a va 2 s .c om*/ process.waitFor(); String output = IOUtils.toString(process.getInputStream()); String errorOutput = IOUtils.toString(process.getErrorStream()); LOG.debug("Shell Output: " + output); if (errorOutput.length() != 0) { LOG.error("Shell Error Output: " + errorOutput); throw new IOException(errorOutput); } return output; } catch (InterruptedException ie) { throw new IOException(ie.toString()); } }
From source file:com.mycompany.mavenproject1.Ex1.java
private String getFileWithUtil(String fileName) { String result = ""; ClassLoader classLoader = getClass().getClassLoader(); try {//from ww w . j a v a2s .co m result = IOUtils.toString(classLoader.getResourceAsStream(fileName)); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:com.flipkart.flux.api.WorkflowSummaryTest.java
@Before public void setUp() throws IOException { objectMapper = new ObjectMapper(); summaryJson = IOUtils .toString(this.getClass().getClassLoader().getResourceAsStream("workflow_summary.json")); }
From source file:com.spider.ssh.SshConfigFileTest.java
/** * Tests to ensure that the data is correctly read and written from the file * @throws Exception/* w ww . jav a 2 s . co m*/ */ @Test public void testParsing() throws Exception { SshConfigFile conf = new SshConfigFile(); String original = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("com/spider/ssh/test1.conf")); conf.parse(getClass().getClassLoader().getResourceAsStream("com/spider/ssh/test1.conf")); Host host; host = conf.getHosts().get(0); assertEquals("test1", host.getName()); assertEquals(3, host.getProperties().size()); assertEquals("ec2-1.compute-1.amazonaws.com", host.getProperties().get("HostName")); assertEquals("ec2-user", host.getProperties().get("User")); assertEquals("~/.ssh/smctest.pem", host.getProperties().get("IdentityFile")); assertEquals(3, conf.getHosts().size()); StringWriter writer = new StringWriter(); conf.save(writer); assertEquals(original, writer.toString()); }
From source file:com.playonlinux.ui.impl.javafx.common.HtmlTemplate.java
public String render(String... replacements) throws IOException { String fileContent = IOUtils.toString(templateUrl.openStream()); return String.format(fileContent, replacements); }
From source file:com.qualogy.qafe.web.CssProviderTest.java
public void testReplaceWithRendererTypeCss() throws Exception { InputStream is = this.getClass().getResourceAsStream("qafe-test.css"); String cssData = IOUtils.toString(is); String css = CssProvider.getInstance().replaceWithRendererTypeCss("gwt", cssData); assertTrue(css.contains("gwt-Button") && css.contains("gwt-TextBox")); }
From source file:com.elasticbox.jenkins.k8s.repositories.api.charts.factory.TestChartFactory.java
@Test public void testPodCreationFromYaml() throws IOException, RepositoryException { final String yaml = IOUtils.toString(this.getClass().getResourceAsStream("podChartManifest.yaml")); final ChartDetails fakeDetails = getFakeChartDetails(); Chart.ChartBuilder builder = new Chart.ChartBuilder(); builder.chartDetails(fakeDetails);/*w w w . j a v a2 s. c o m*/ ManifestFactory.addManifest(yaml, builder); final Chart build = builder.build(); assertTrue("At least it should contains one rc", 1 == build.getPods().size()); }
From source file:com.github.rnewson.couchdb.lucene.util.ErrorPreservingResponseHandler.java
public String handleResponse(final org.ektorp.http.HttpResponse response) throws HttpResponseException, IOException { String str = IOUtils.toString(response.getContent()); if (response.getCode() >= 300) { throw new HttpResponseException(response.getCode(), str); }// w w w .jav a 2 s . c om return str; }
From source file:com.seer.datacruncher.fileupload.TxtFileReadObject.java
@Override public String parseStream(long schemaId, InputStream is) { try {//www . j av a 2s. com return IOUtils.toString(is); } catch (IOException e) { logger.error("Error occured during fetch records from excel file.", e); return ""; } }