List of usage examples for java.io Writer toString
public String toString()
From source file:com.basistech.rosette.dm.json.plain.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 = AnnotatedDataModelModule.setupObjectMapper(new ObjectMapper()); ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter(); Writer sw = new StringWriter(); objectWriter.writeValue(sw, text);/*w w w .ja va2 s . c o 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.basistech.rosette.dm.json.plain.ExtendedPropertyTest.java
@Test public void testExtendedPropertyOnAttribute() 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"); emBuilder.extendedProperty("extra_key", "extra_value"); emListBuilder.add(emBuilder.build()); builder.entityMentions(emListBuilder.build()); AnnotatedText text = builder.build(); ObjectMapper mapper = AnnotatedDataModelModule.setupObjectMapper(new ObjectMapper()); ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter(); Writer sw = new StringWriter(); objectWriter.writeValue(sw, text);// w w w .j a v a 2s .co m ObjectReader reader = mapper.readerFor(AnnotatedText.class); AnnotatedText deserialized = reader.readValue(sw.toString()); assertEquals("extra_value", deserialized.getEntityMentions().get(0).getExtendedProperties().get("extra_key")); }
From source file:com.boxedfolder.domain.util.DateTimeSerializerTests.java
@Test public void testSerializer() throws Exception { Writer writer = new StringWriter(); JsonGenerator generator = new JsonFactory().createGenerator(writer); serializer.serialize(dateTime, generator, mapper.getSerializerProvider()); generator.close();// w ww. j ava 2s .com assertEquals("\"2015-07-22T07:39:16.302Z\"", writer.toString()); // Output }
From source file:org.nuxeo.launcher.info.MessageInfoLogger.java
public void debug(Object... args) { for (Object arg : args) { if (arg instanceof String) { debug((String) arg);/* w w w . j av a 2s . c o m*/ } else if (arg instanceof Throwable) { Writer stringWriter = new StringWriter(); PrintWriter stackWriter = new PrintWriter(stringWriter); ((Throwable) arg).printStackTrace(stackWriter); debug(stringWriter.toString()); } else { debug(arg.toString()); } } }
From source file:jp.co.cyberagent.jenkins.plugins.DeployStrategyIOs.java
private FilePath findPlistFile() { try {// www .j a v a 2 s .c o m List<FilePath> plistFiles = FileListUtil.listFilesRecursively(getBuild().getWorkspace(), new PlistFileFilter(mIpaFile)); if (plistFiles.isEmpty()) { return null; } else if (plistFiles.size() > 1) { getLogger().println(TAG + "Error: Found multiple Info.plist files in *.app folders."); return null; } return plistFiles.get(0); } catch (Exception e) { Writer writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); e.printStackTrace(printWriter); getLogger().println(writer.toString()); } return null; }
From source file:org.cartoweb.stats.BaseStats.java
public void run() { try {// w w w . j a va2s . co m runImpl(); } catch (Throwable e) { if (LOGGER.isDebugEnabled()) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter); LOGGER.error(result.toString()); } else { LOGGER.error(e.toString()); } } }
From source file:mupomat.utility.LongLatService.java
public void getLongitudeLatitude(String address) { try {//from www. ja va 2s . co m StringBuilder urlBuilder = new StringBuilder(GEOCODE_REQUEST_URL); if (StringUtils.isNotBlank(address)) { urlBuilder.append("&address=").append(URLEncoder.encode(address, "UTF-8")); } final GetMethod getMethod = new GetMethod(urlBuilder.toString()); try { httpClient.executeMethod(getMethod); Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()); int data = reader.read(); char[] buffer = new char[1024]; Writer writer = new StringWriter(); while ((data = reader.read(buffer)) != -1) { writer.write(buffer, 0, data); } String result = writer.toString(); System.out.println(result.toString()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader("<" + writer.toString().trim())); Document doc = db.parse(is); strLatitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lat/text()"); System.out.println("Latitude:" + strLatitude); strLongtitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lng/text()"); System.out.println("Longitude:" + strLongtitude); } finally { getMethod.releaseConnection(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.ofbiz.content.data.DataResourceWorker.java
public static String renderDataResourceAsText(Delegator delegator, String dataResourceId, Map<String, Object> templateContext, Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException { Writer writer = new StringWriter(); renderDataResourceAsText(delegator, dataResourceId, writer, templateContext, locale, targetMimeTypeId, cache, null);//from w ww.j a v a2s . co m return writer.toString(); }
From source file:org.cvit.cabig.dmr.cmef.server.ModelsResource.java
@Get("htm|html") public Representation listModelsHtml() { Iterator<ComputationalModel> models = listModels(); List<ComputationalModel> modelList = new ArrayList<ComputationalModel>(); while (models.hasNext()) { modelList.add(models.next());// ww w .ja v a 2 s. c om } SimpleHash root = new SimpleHash(); root.put("entryName", entryName); root.put("models", modelList); root.put("funcs", new TemplateFunctions()); Configuration config = new Configuration(); try { Template template = new Template("models.html", new StringReader(HTML_FTL), config); Writer out = new StringWriter(); template.process(root, out); setStatus(Status.SUCCESS_OK); return new StringRepresentation(out.toString(), MediaType.TEXT_HTML); } catch (IOException e) { setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation("Exception reading template: " + e.getMessage()); } catch (TemplateException e) { setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation("Template error: " + e.getMessage()); } }
From source file:com.ibm.rpe.web.service.docgen.impl.GenerateBaseTemplate.java
public final void prettyPrint(Document xml) throws Exception { Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); tf.setOutputProperty(OutputKeys.INDENT, "yes"); Writer out = new StringWriter(); tf.transform(new DOMSource(xml), new StreamResult(out)); System.out.println(out.toString()); }