List of usage examples for java.io ByteArrayOutputStream toString
public synchronized String toString()
From source file:Main.java
public static String getStringFromInputStream(InputStream is) { if (is == null) { return null; }/*from w w w . j av a 2 s. c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4 * 1024]; int len = 0; try { while ((len = is.read(buffer)) != -1) { baos.write(buffer, 0, len); } is.close(); } catch (Exception e) { } return baos.toString(); }
From source file:com.micro.rent.common.comm.aio.AsyncClientHttpExchangeFutureCallback.java
public static String readInputStream(InputStream input) throws IOException { byte[] buffer = new byte[128]; int len = 0;/* ww w .ja v a 2 s . c om*/ ByteArrayOutputStream bytes = new ByteArrayOutputStream(); while ((len = input.read(buffer)) >= 0) { bytes.write(buffer, 0, len); } return bytes.toString(); }
From source file:fr.aliasource.webmail.server.proxy.client.http.DOMUtils.java
public static void logDom(Document doc) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {//from w w w . ja v a 2 s .com serialise(doc, out); System.out.println("DOM log:\n" + out.toString()); } catch (TransformerException e) { e.printStackTrace(); } }
From source file:com.philips.hsdp.feed.HelloWorldManager.java
public static String getStringFromHttpResponse(HttpResponse inResponse) { String responseString = null; try {// w w w . j a v a 2s . c o m ByteArrayOutputStream out = new ByteArrayOutputStream(); inResponse.getEntity().writeTo(out); out.close(); responseString = out.toString(); } catch (IOException e) { e.printStackTrace(); } return responseString; }
From source file:Main.java
/** * Creates from the given Object an xml string. * //from w w w .ja va2 s. c o m * @param <T> * the generic type of the return type * @param obj * the obj to transform to an xml string. * @return the xml string */ public static <T> String toXmlWithXMLEncoder(final T obj) { XMLEncoder enc = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { enc = new XMLEncoder(baos); enc.writeObject(obj); enc.close(); enc = null; } finally { if (enc != null) { enc.close(); } } return baos.toString(); }
From source file:edu.kit.cockpit.valuationserver.pollgenerator.PollGenerator.java
/** * Generate a poll message based on an evaluation * /*from w w w . j a va2 s.com*/ * @param attribTypeList * @param eval * @param isVisible * @return * @throws DatatypeConfigurationException */ public static PollType createPoll(EvaluationE eval, boolean isVisible) throws DatatypeConfigurationException { // List<AttributeType> attribTypeList = // getComparableSFMAttributes(eval); PollType poll = new PollType(); poll.setType(POLL_TYPE_ASPECT_COMPARISON); assert (eval.getId() != null); poll.setEvaluationId(String.valueOf(eval.getId())); poll.setVisible(isVisible); if (eval.getPollDeadline() != null) poll.setEndDate(DateUtil.getXmlGregCal(eval.getPollDeadline())); if (eval.getName() != null) poll.setTitle(eval.getName()); if (eval.getDescription() != null) poll.setSubtitle(eval.getDescription()); if (eval.getServiceId() != null) poll.setServiceId(eval.getServiceId()); if (eval.getPollId() != null) poll.setPollId(eval.getPollId()); // generate aspects from exclusive pairs of attribute types poll.setAspects(new PollType.Aspects()); String[][] attribArray = getAttributePairings(eval); for (int i = 0; i < attribArray.length; i++) { PollType.Aspects.Aspect aspect = new PollType.Aspects.Aspect(); aspect.setFeature1(attribArray[i][0]); aspect.setFeature2(attribArray[i][1]); poll.getAspects().getAspect().add(aspect); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); JAXB.marshal(poll, baos); log.info("Poll generated: " + System.getProperty("line.separator") + baos.toString()); return poll; }
From source file:de.awtools.basic.AWTools.java
/** * Konvertiert die Stacktrace Meldungen einer Exception in einen String. * // w ww . java 2s. c o m * @param ex Die zu konvertierende Exception. * @return Der Stacktrace der Exception als String. */ public static String stacktraceToString(final Exception ex) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); ex.printStackTrace(ps); return baos.toString(); }
From source file:Main.java
public static String readFile(String path) { try {/* w w w.j a va 2s . c o m*/ FileInputStream in = new FileInputStream(path); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte buffer[] = new byte[1024]; int count = 0; while ((count = in.read(buffer)) != -1) { if (out != null) { out.write(buffer, 0, count); } } return out.toString(); } catch (FileNotFoundException e) { Log.e(TAG, "File not found: " + path, e); } catch (IOException e) { Log.e(TAG, "Error while reading file: " + path, e); } return null; }
From source file:gov.va.vinci.leo.tools.LeoUtils.java
/** * Load the config file(s).// w w w .j a v a 2 s. c o m * * @param environment name of the environment to load * @param configFilePaths paths the config files to load, local or remote * @return ConfigObject with accumulated variables representing the environment * @throws IOException if there is a problem reading the config files */ public static ConfigObject loadConfigFile(String environment, String... configFilePaths) throws IOException { ConfigSlurper slurper = new ConfigSlurper(environment); ConfigObject config = new ConfigObject(); ClassLoader cl = ClassLoader.getSystemClassLoader(); for (String filePath : configFilePaths) { InputStream in = cl.getResourceAsStream(filePath); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(in, out); String resourceAsString = out.toString(); config.merge(slurper.parse(resourceAsString)); } return config; }
From source file:URLConnectionTest.java
/** * Computes the Base64 encoding of a string * @param s a string//from w w w . jav a2 s. co m * @return the Base 64 encoding of s */ public static String base64Encode(String s) { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); Base64OutputStream out = new Base64OutputStream(bOut); try { out.write(s.getBytes()); out.flush(); } catch (IOException e) { } return bOut.toString(); }