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:ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException.java
public static NonFhirResponseException newInstance(int theStatusCode, String theContentType, Reader theReader) { String responseBody = ""; try {/*from w w w. ja v a 2s . co m*/ responseBody = IOUtils.toString(theReader); } catch (IOException e) { IOUtils.closeQuietly(theReader); } NonFhirResponseException retVal; if (isBlank(theContentType)) { retVal = new NonFhirResponseException(theStatusCode, "Response contains no Content-Type"); } else if (theContentType.contains("text")) { retVal = new NonFhirResponseException(theStatusCode, "Response contains non FHIR Content-Type '" + theContentType + "' : " + responseBody); } else { retVal = new NonFhirResponseException(theStatusCode, "Response contains non FHIR Content-Type '" + theContentType + "'"); } retVal.setResponseBody(responseBody); return retVal; }
From source file:com.hp.autonomy.searchcomponents.hod.search.fields.HodSearchResultDeserializerTest.java
@BeforeClass public static void init() throws IOException { sampleJson = IOUtils.toString( HodSearchResultDeserializerTest.class.getResourceAsStream("/sampleHodQueryResponse.json")); }
From source file:com.geocent.owf.openlayers.handler.DefaultHandler.java
@Override public String handleContent(HttpServletResponse response, InputStream responseStream) throws IOException { response.setContentType(contentType); return IOUtils.toString(responseStream); }
From source file:com.evermal.xtractor.MaintenanceClassifierWordMatcher.java
public void processFile(String fileName) throws IOException { FileInputStream fileStream = new FileInputStream(fileName); String file = IOUtils.toString(fileStream); String[] splited = file.split("<EndOfFile>"); for (String commentsInOneClass : splited) { CommitFile commitFile = new CommitFile(commentsInOneClass); readCommits(commitFile, fileName); }/*ww w . ja v a 2 s . c o m*/ StringBuilder sb = new StringBuilder(); sb.append(System.getProperty("line.separator")); sb.append("numberOfFilesAnalyzed = " + FileCounter.getNumberOfFilesAnalyzed()); sb.append(System.getProperty("line.separator")); sb.append("numberOfCommitMessagesAnalyzed = " + FileCounter.getNumberOfCommitMessagesAnalyzed()); sb.append(System.getProperty("line.separator")); sb.append("correctiveChange = " + FileCounter.getCorrectiveChange()); sb.append(System.getProperty("line.separator")); sb.append("adaptativeChange = " + FileCounter.getAdaptativeChange()); sb.append(System.getProperty("line.separator")); sb.append("perfectiveChange = " + FileCounter.getPerfectiveChange()); sb.append(System.getProperty("line.separator")); sb.append("featureAdditionChange = " + FileCounter.getFeatureAdditionChange()); sb.append(System.getProperty("line.separator")); sb.append("nonFunctionalChange = " + FileCounter.getNonFunctionalChange()); sb.append(System.getProperty("line.separator")); sb.append("withoutClassificationChange = " + FileCounter.getWithoutClassificationChange()); FileUtils.WriteOrUpdateFile(FileUtils.getStatisticFileName(fileName), sb.toString()); FileUtils.WriteOrUpdateFile(FileUtils.getBugIdFileName(fileName), FileCounter.getBugIdList()); }
From source file:io.github.bluemarlin.util.BluemarlineUtil.java
public static String loadFromClassPath(Class<?> clazz, String classPath) { System.out.println("loadFromClassPath: " + classPath); String page = ""; try {//w w w.j a v a 2s.c o m InputStream is = clazz.getResourceAsStream(classPath); page = IOUtils.toString(is); } catch (IOException e) { System.out.println("Exception" + e.getMessage()); // won't likely happen since file is in classpath e.printStackTrace(); } return page; }
From source file:com.github.bjoern2.codegen.util.LicenseUtils.java
private static String loadTemplate(String filename) { InputStream input = LicenseUtils.class.getResourceAsStream(filename); try {// ww w . ja v a 2s. c om return IOUtils.toString(input); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:at.ac.tuwien.dsg.cloud.utilities.gateway.registry.UserControllerTest.java
private static String readJsonFileHelper(String fileName) throws IOException { return IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)); }
From source file:com.thoughtworks.xstream.benchmark.strings.targets.BigString.java
public BigString() { try {//from w w w . ja va2 s . com string = IOUtils.toString(getClass().getResourceAsStream("eclipse-build-log.txt")); } catch (IOException e) { throw new RuntimeException("Cannot create big String target", e); } }
From source file:com.nebel_tv.content.utils.ConnectionUtils.java
/** * * @param url//from w w w .j a v a 2s.c o m * @return * @throws Exception */ public static InputStream getResponseAsStream(String url) throws Exception { if (ids.empty()) { init(); } String developerId = ids.pop(); url = url + "&Developerid=" + developerId; try { String result = IOUtils.toString(new URL(url)); ids.push(developerId); return new ByteArrayInputStream(result.getBytes()); } catch (MalformedURLException ex) { Logger.getLogger(ConnectionUtils.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ConnectionUtils.class.getName()).log(Level.WARNING, null, ex); } return null; }
From source file:com.codeabovelab.dm.mail.service.MailUtils.java
/** * Convert message body to text if possible, otherwise throw exception. * @param body// w ww. ja v a 2 s .c o m * @return */ public static String toPlainText(MailBody body) throws MailBadMessageException { MimeType mimeType = body.getMimeType(); boolean containsMime = false; for (MimeType type : mimeTypeSet) { containsMime = containsMime || type.includes(mimeType); } if (!containsMime) { throw new MailBadMessageException("Message contains body with unsupported contentType: " + mimeType); } try (Reader r = body.getReader()) { return IOUtils.toString(r); } catch (IOException e) { throw new MailBadMessageException(e); } }