List of usage examples for java.io Writer toString
public String toString()
From source file:de.extra.client.plugins.outputplugin.ws.WsOutputPluginNotWorking.java
/** * Test method for//from w w w . j a v a 2 s. c o m * {@link de.extra.client.plugins.outputplugin.ws.WsOutputPlugin#outputData(java.io.InputStream)} */ @Test public void testOutputData() throws Exception { final RequestTransport requestTransport = extraUnmarschaller .unmarshal(new ByteArrayInputStream(request2.getBytes()), RequestTransport.class); final ResponseTransport responseTransport = plugin.outputData(requestTransport); final Writer writer = new StringWriter(); final StreamResult streamResult = new StreamResult(writer); marshaller.marshal(responseTransport, streamResult); logger.debug(writer.toString()); }
From source file:com.basistech.rosette.dm.json.array.ExtendedPropertyTest.java
@Test public void morphoAnalysisListExtProps() throws Exception { Token.Builder tokBuilder = new Token.Builder(0, 0, "nothing"); HanMorphoAnalysis.Builder hmaBuilder = new HanMorphoAnalysis.Builder(); hmaBuilder.addReading("Proust").extendedProperty("spill", "ink"); tokBuilder.addAnalysis(hmaBuilder.build()); ArabicMorphoAnalysis.Builder armaBuilder = new ArabicMorphoAnalysis.Builder(); armaBuilder.definiteArticle(true).extendedProperty("some", "apples"); tokBuilder.addAnalysis(armaBuilder.build()); ObjectMapper mapper = AnnotatedDataModelArrayModule.setupObjectMapper(new ObjectMapper()); ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter(); Writer sw = new StringWriter(); objectWriter.writeValue(sw, tokBuilder.build()); ObjectReader reader = mapper.readerFor(Token.class); Token deserialized = reader.readValue(sw.toString()); HanMorphoAnalysis ma1 = (HanMorphoAnalysis) deserialized.getAnalyses().get(0); assertEquals("ink", ma1.getExtendedProperties().get("spill")); ArabicMorphoAnalysis ma2 = (ArabicMorphoAnalysis) deserialized.getAnalyses().get(1); assertEquals("apples", ma2.getExtendedProperties().get("some")); }
From source file:com.dubic.dc.dev.assist.services.ModuleService.java
/** * uses velocity to evaluate to resolve a simple string template * * @param str the template string e.g 'welcome ${name}' * @param params/*from w ww . j a va2 s.c o m*/ * @return the resolved string */ public String resolve(String str, Map<String, Object> params) { VelocityContext context = new VelocityContext(); for (String key : params.keySet()) { context.put(key, params.get(key)); } Writer w = new StringWriter(); Velocity.evaluate(context, w, "MODULE", str); return w.toString(); }
From source file:com.basistech.rosette.dm.json.plain.ExtendedPropertyTest.java
@Test public void morphoAnalysisListExtProps() throws Exception { Token.Builder tokBuilder = new Token.Builder(0, 0, "nothing"); HanMorphoAnalysis.Builder hmaBuilder = new HanMorphoAnalysis.Builder(); hmaBuilder.addReading("Proust").extendedProperty("spill", "ink"); tokBuilder.addAnalysis(hmaBuilder.build()); ArabicMorphoAnalysis.Builder armaBuilder = new ArabicMorphoAnalysis.Builder(); armaBuilder.definiteArticle(true).extendedProperty("some", "apples"); tokBuilder.addAnalysis(armaBuilder.build()); ObjectMapper mapper = AnnotatedDataModelModule.setupObjectMapper(new ObjectMapper()); ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter(); Writer sw = new StringWriter(); objectWriter.writeValue(sw, tokBuilder.build()); ObjectReader reader = mapper.readerFor(Token.class); Token deserialized = reader.readValue(sw.toString()); HanMorphoAnalysis ma1 = (HanMorphoAnalysis) deserialized.getAnalyses().get(0); assertEquals("ink", ma1.getExtendedProperties().get("spill")); ArabicMorphoAnalysis ma2 = (ArabicMorphoAnalysis) deserialized.getAnalyses().get(1); assertEquals("apples", ma2.getExtendedProperties().get("some")); }
From source file:org.mule.modules.jive.JerseyJiveFacade.java
private String toXml(final CustomOp op, final Map<String, Object> entity) { final Writer writer = new StringWriter(); map2xml(op.getRootTagElementName(), entity, writer); return writer.toString(); }
From source file:jp.sourceforge.reflex.core.ResourceMapper.java
public String toJSON(Object entity) { if (entity == null) return null; Writer writer = new StringWriter(); jsonc.marshal(entity, writer);/*from w ww . j a v a 2 s . c om*/ return writer.toString(); }
From source file:com.basistech.rosette.dm.json.array.ExtendedPropertyTest.java
@Test public void testExtendedPropertyOnListAttribute() throws Exception { // 012345678901234567890 String rawText = "Cuthbert Girdlestone"; AnnotatedText.Builder builder = new AnnotatedText.Builder().data(rawText); ListAttribute.Builder<com.basistech.rosette.dm.EntityMention> emListBuilder = new ListAttribute.Builder<>( com.basistech.rosette.dm.EntityMention.class); com.basistech.rosette.dm.EntityMention.Builder emBuilder = new com.basistech.rosette.dm.EntityMention.Builder( 0, 20, "PERSON"); emListBuilder.extendedProperty("extra_key", "extra_value"); emListBuilder.add(emBuilder.build()); builder.entityMentions(emListBuilder.build()); AnnotatedText text = builder.build(); ObjectMapper mapper = AnnotatedDataModelArrayModule.setupObjectMapper(new ObjectMapper()); ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter(); Writer sw = new StringWriter(); objectWriter.writeValue(sw, text);//w ww .ja v a2 s . co m ObjectReader reader = mapper.readerFor(AnnotatedText.class); AnnotatedText deserialized = reader.readValue(sw.toString()); assertEquals("extra_value", deserialized.getEntityMentions().getExtendedProperties().get("extra_key")); }
From source file:com.camel.drools.expert.sample.service.OrderAutoFlowService.java
/** * FreeMarker?drools dslr/*from w w w .j av a 2 s . com*/ * @param oafr ? */ public String generDslrFromFtlFile(UserRule userRule, Template temp) { Map root = new HashMap(); root.put("userRule", userRule); Writer out = new StringWriter(); try { temp.process(root, out); } catch (TemplateException | IOException e) { e.printStackTrace(); } return out.toString(); }
From source file:com.veight.mail.template.MailTemplateLocal.java
public String makeContent(String templateName, Map<String, String> root) { Writer out = null; try {/*from w w w.jav a2 s . c om*/ Template template = configuration.getTemplate(templateName); out = new StringWriter(); template.process(root, out); out.flush(); return out.toString(); } catch (IOException | TemplateException ex) { logger.error("Fail to get content from freemaker. [mailTemplate={}][mail={}]", templateName, ex); } finally { if (out != null) { try { out.close(); } catch (IOException ex) { logger.error("Fail to close StringWriter.", ex); } } } return StringUtils.EMPTY; }
From source file:com.asual.summer.core.ErrorController.java
@ResponseViews({ AbstractResponseView.class, StringView.class }) public ModelAndView error(Exception ex) { Writer stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ex.printStackTrace(printWriter);/*w w w . j a v a2s.c o m*/ ModelMap model = new ModelMap(); model.addAttribute("error", ex); model.addAttribute("stackTrace", stringWriter.toString()); return new ModelAndView("/error", model); }