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.demonwav.mcdev.platform.mcp.version.McpVersion.java
@Nullable public static McpVersion downloadData() { try (InputStream in = new URL("http://export.mcpbot.bspk.rs/versions.json").openStream()) { String text = IOUtils.toString(in); final Type tokenType = new TypeToken<Map<String, Map<String, List<Integer>>>>() { }.getType();/*from w w w . j a va 2 s . com*/ final Map<String, Map<String, List<Integer>>> map = new Gson().fromJson(text, tokenType); final McpVersion version = new McpVersion(); version.map = map; return version; } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount.java
public static VaultConfigMount fromLocalFile(File localFile, String desiredPath) { String contents;/* w w w. j a v a 2 s . c o m*/ try { String unencodedContents = IOUtils.toString(new FileInputStream(localFile)); contents = Base64.getEncoder().encodeToString(unencodedContents.getBytes()); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Failed to read local config file: " + localFile, e); } return new VaultConfigMount().setContents(contents).setFile(desiredPath); }
From source file:ch.oakmountain.tpa.web.TpaPersistorUtils.java
public static void copyFromResourceToDir(String fileName, String outputDir, String prefix) throws IOException { String content = IOUtils.toString( TpaWebPersistor.class.getResourceAsStream(File.separator + prefix + File.separator + fileName)); FileUtils.writeStringToFile(new File(outputDir + File.separator + prefix + File.separator + fileName), content);/*from w ww. j a v a 2s . com*/ }
From source file:com.floreantpos.ui.util.StreamUtils.java
public static String toString(InputStream in) throws IOException { if (in == null) { return ""; //$NON-NLS-1$ }//from w w w . ja v a 2 s. c om try { return IOUtils.toString(in); } finally { IOUtils.closeQuietly(in); } }
From source file:myproject.MyServer.java
public static void Query(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/* w w w . j ava 2s.c o m*/ String jsonString = IOUtils.toString(request.getInputStream()); JSONObject json = (JSONObject) JSONValue.parse(jsonString); String query = (String) json.get("query"); String result = database.runQuery(query); response.getWriter().write(result); } catch (Exception ex) { JSONObject output = new JSONObject(); output.put("error", "Connection failed: " + ex.getMessage()); response.getWriter().write(JSONValue.toJSONString(output)); } }
From source file:latexstudio.editor.files.FileService.java
public static String readFromStream(InputStream stream) { try {/*from w w w . j a v a2 s. c om*/ return IOUtils.toString(stream); } catch (IOException ex) { Exceptions.printStackTrace(ex); } finally { IOUtils.closeQuietly(stream); } return null; }
From source file:com.google.gwt.benchmark.compileserver.server.manager.CliInteractorTest.java
License:asdf
private static String getTestOutput() throws IOException { FileInputStream inputStream = null; try {//w w w. j a v a 2s.com inputStream = new FileInputStream(new File("./target/test-out")); String out = IOUtils.toString(inputStream); // Cut off new line char return out.substring(0, out.length() - 1); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:de.hybris.platform.secureportaladdon.tests.util.B2BSecurePortalTestsUtil.java
public static String impexFileToString(final String file) throws Exception { String impexContent = null;//w ww . jav a 2 s .co m InputStream inputStream = null; try { inputStream = ServicelayerTest.class.getResourceAsStream(file); impexContent = IOUtils.toString(inputStream); } finally { inputStream.close(); } return impexContent; }
From source file:dz.jtsgen.processor.helper.ReferenceHelper.java
public static void assertEquals(JavaFileObject testeeFile, String referenceFile) throws IOException { String testee = IOUtils.toString(testeeFile.openReader(true)); String reference = IOUtils.toString(createReferenceStreamFor(referenceFile), Charset.forName("UTF-8")); Assert.assertEquals(reference, testee); }
From source file:com.redhat.red.build.koji.testutil.TestResourceUtils.java
public static String readTestResourceString(String resource) throws IOException { try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { return IOUtils.toString(in); }/*from w w w.j a va 2s .c om*/ }