List of usage examples for java.io Writer toString
public String toString()
From source file:org.codehaus.groovy.grails.plugins.spring.ws.AbstractGrailsEndpointClass.java
public Source invoke(Source request) throws Exception { Writer responseWriter = createResponseWriter(); getMetaClass().invokeMethod(getReferenceInstance(), INVOKE, new Object[] { createRequest(request), createResponse(responseWriter) }); return new StringSource(responseWriter.toString()); }
From source file:org.broadleafcommerce.core.web.processor.ProductOptionValueProcessor.java
@Override protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) { Expression expression = (Expression) StandardExpressions.getExpressionParser(arguments.getConfiguration()) .parseExpression(arguments.getConfiguration(), arguments, element.getAttributeValue(attributeName)); ProductOptionValue productOptionValue = (ProductOptionValue) expression .execute(arguments.getConfiguration(), arguments); ProductOptionValueDTO dto = new ProductOptionValueDTO(); dto.setOptionId(productOptionValue.getProductOption().getId()); dto.setValueId(productOptionValue.getId()); dto.setValueName(productOptionValue.getAttributeValue()); if (productOptionValue.getPriceAdjustment() != null) { dto.setPriceAdjustment(productOptionValue.getPriceAdjustment().getAmount()); }/*from w ww.ja va 2 s. com*/ try { ObjectMapper mapper = new ObjectMapper(); Writer strWriter = new StringWriter(); mapper.writeValue(strWriter, dto); element.setAttribute("data-product-option-value", strWriter.toString()); element.removeAttribute(attributeName); return ProcessorResult.OK; } catch (Exception ex) { LOG.error("There was a problem writing the product option value to JSON", ex); } return null; }
From source file:com.si.xe.trader.listener.OrderbookExternalListener.java
private void doHandle(TradeExecutedEvent event) throws IOException { String jsonObjectAsString = createJsonInString(event); HttpPost post = new HttpPost(remoteServerUri); post.setEntity(new StringEntity(jsonObjectAsString)); post.addHeader("Content-Type", "application/json"); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() != 200) { Writer writer = new StringWriter(); IOUtils.copy(response.getEntity().getContent(), writer); logger.warn("Error while sending event to external system: {}", writer.toString()); }/* ww w .j a v a2s .c o m*/ }
From source file:nl.clockwork.mule.common.transformer.AbstractXSLTransformer.java
@Override public Object transform(MuleMessage message, String outputEncoding) throws TransformerException { try {// w w w .j a v a 2 s. com Transformer transformer = templates.newTransformer(); for (String name : parameters.keySet()) transformer.setParameter(name, parameters.get(name)); StreamSource xmlsource = new StreamSource(new StringReader(message.toString())); Writer writer = new StringWriter(); StreamResult output = new StreamResult(writer); transformer.transform(xmlsource, output); writer.flush(); message.setPayload(writer.toString()); return message; } catch (Exception e) { throw new TransformerException(this, e); } }
From source file:org.apache.ofbiz.content.data.DataResourceWorker.java
public static String getDataResourceText(GenericValue dataResource, String mimeTypeId, Locale locale, Map<String, Object> context, Delegator delegator, boolean cache) throws IOException, GeneralException { Writer out = new StringWriter(); writeDataResourceText(dataResource, mimeTypeId, locale, context, delegator, out, cache); return out.toString(); }
From source file:com.jaxio.celerio.output.XmlCodeFormatter.java
public String format(String unformattedXml) { if (!xmlFormatterConfig.isEnableXmlFormatter()) { return unformattedXml; }/*from w w w .j a v a 2s . c om*/ try { final Document document = parseXmlFile(unformattedXml); OutputFormat format = new OutputFormat(document); format.setLineWidth(xmlFormatterConfig.getMaximumLineWidth()); format.setIndenting(true); format.setIndent(xmlFormatterConfig.getIndent()); format.setLineSeparator(System.getProperty("line.separator")); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); return out.toString(); } catch (Exception e) { log.warn("Could not format the content: " + unformattedXml); throw new RuntimeException(e); } }
From source file:org.nohope.jongo.JacksonProcessor.java
@Override public <T> String marshall(final T obj) { try {/* w w w . ja v a 2 s.co m*/ final Writer writer = new StringWriter(); getMapper().writeValue(writer, obj); return writer.toString(); } catch (Exception e) { final String message = String.format("Unable to marshall json from: %s", obj); throw new MarshallingException(message, e); } }
From source file:uk.co.md87.android.common.ExceptionHandler.java
public void uncaughtException(Thread t, Throwable e) { String timestamp = String.valueOf(System.currentTimeMillis()); final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter);//from www . ja v a 2 s. co m String stacktrace = result.toString(); printWriter.close(); String filename = timestamp + ".stacktrace"; sendToServer(stacktrace, filename); defaultUEH.uncaughtException(t, e); }
From source file:org.apache.servicemix.http.endpoints.SerializedMarshaler.java
/** * Marshal the byte content of the input stream to an XML source. This method is marshaling the contents of the * Spring <a//from www . j a va 2 s. c o m * href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocation.html">RemoteInvocation</a> * object. Below is an example of what this method emits: * * <pre> * <?xml version="1.0" encoding="UTF-8"?><org.springframework.remoting.support.RemoteInvocation> * <methodName>login</methodName> * <parameterTypes> * <java-class>java.lang.String</java-class> * <java-class>java.lang.String</java-class> * </parameterTypes> * <arguments> * <string>foo</string> * <string>bar</string> * </arguments> * </org.springframework.remoting.support.RemoteInvocation> * </pre> * * @param is - * input stream to read the object from * @return xml source * @throws IOException * @throws ClassNotFoundException */ private Source marshal(InputStream is) throws IOException, ClassNotFoundException { Object obj = new ObjectInputStream(is).readObject(); Writer w = new StringWriter(); XStream xstream = new XStream(new DomDriver()); xstream.toXML(obj, w); String request = w.toString(); if (log.isDebugEnabled()) { log.debug("Remote invocation request: " + request); } return new StringSource(request); }
From source file:com.cognifide.aet.rest.XUnitServlet.java
private InputStream generateXML(Testsuites xUnitModel) throws JAXBException, IOException { Writer writer = new StringWriter(); writer.write(XML_HEADER);/*from w w w.j av a 2 s . c o m*/ prepareJaxbMarshaller().marshal(xUnitModel, writer); return IOUtils.toInputStream(writer.toString(), Charsets.UTF_8); }