articles
15 уровень

Java Code Examples for java.io.StringWriter. Часть 2

Пост из группы Архив info.javarush.ru
3681 участников
Example 25 Project: wso2-synapse File: JsonXMLMapperTest.java @Test public void testWriteXmlRootElement() throws Exception { JsonXMLMapper mapper = new JsonXMLMapper(SampleRootElement.class); StringWriter writer = new StringWriter(); SampleRootElement value = new SampleRootElement(); mapper.writeObject(writer, value); writer.close(); Assert.assertEquals("{\"sampleRootElement\":null}", writer.toString()); } Example 26 Project: koubei-mongo File: MongoUtil.java public static String objectToJson(Object object) throws IOException { String json = null; ObjectMapper mapper = MongoMapper.getInstance(); StringWriter writer = new StringWriter(); JsonGenerator generator = new JsonFactory().createJsonGenerator(writer); mapper.writeValue(generator, object); generator.close(); json = writer.toString(); writer.close(); return json; } Example 27 Project: sw606f13 File: StationConfiguration.java public String writeStation() throws IOException { StringWriter sWriter = new StringWriter(1024); sWriter.write(String.valueOf(this.category)); for(Long pictogram : acceptPictograms) { sWriter.append(","); sWriter.write(String.valueOf(pictogram)); } String result = sWriter.toString(); sWriter.close(); return result; } Example 28 Project: pentaho-metadata-editor File: Const.java public static final String getStackTracker(Throwable e) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); String string = stringWriter.getBuffer().toString(); try { stringWriter.close(); } catch(IOException ioe) {} // is this really required? return string; } Example 29 Project: violetumleditor File: XHTMLPersistenceService.java @Override public IGraph read(InputStream in) throws IOException { InputStreamReader reader = new InputStreamReader(in, "UTF-8"); XHTMLPersistenceServiceParserGetter kit = new XHTMLPersistenceServiceParserGetter(); HTMLEditorKit.Parser parser = kit.getParser(); StringWriter writer = new StringWriter(); HTMLEditorKit.ParserCallback callback = new XHTMLPersistenceServiceParserCallback(writer); parser.parse(reader, callback, true); String xmlContent = writer.toString(); InputStream xmlContentStream = new ByteArrayInputStream(xmlContent.getBytes()); IGraph graph = this.xstreamService.read(xmlContentStream); reader.close(); xmlContentStream.close(); reader.close(); writer.close(); return graph; } Example 30 Project: dswarm-graph-neo4j File: MaintainResource.java @DELETE @Path("/delete") @Produces("application/json") public Response cleanGraph(@Context final GraphDatabaseService database) throws IOException, DMPGraphException { MaintainResource.LOG.debug("start cleaning up the db"); final long deleted = deleteSomeStatements(database); MaintainResource.LOG.debug("finished delete-all-entities TXs"); MaintainResource.LOG.debug("start legacy indices clean-up"); // TODO: maybe separate index clean-up + observe index clean-up // => maybe we also need to do a label + relationship types clean-up ... => this is not supported right now ... deleteSomeLegacyIndices(database); MaintainResource.LOG.debug("finished legacy indices clean-up"); MaintainResource.LOG.debug("start schema indices clean-up"); deleteSomeSchemaIndices(database); MaintainResource.LOG.debug("finished schema indices clean-up"); MaintainResource.LOG.debug("finished cleaning up the db"); final StringWriter out = new StringWriter(); final JsonGenerator generator = simpleObjectMapper.getFactory().createGenerator(out); generator.writeStartObject(); generator.writeNumberField("deleted", deleted); generator.writeEndObject(); generator.flush(); generator.close(); final String result = out.toString(); out.flush(); out.close(); return Response.ok(result, MediaType.APPLICATION_JSON_TYPE).build(); } Example 31 Project: org.openscience.cdk File: RModel.java private void loadRFunctionsAsStrings(Rengine evaluator) { String[] scripts = { "helper.R", }; String scriptPrefix = "org/openscience/cdk/qsar/model/data/"; for (int i = 0; i < scripts.length; i++) { String scriptLocator = scriptPrefix + scripts[i]; try { InputStreamReader reader = new InputStreamReader( this.getClass().getClassLoader().getResourceAsStream(scriptLocator)); BufferedReader inFile = new BufferedReader(reader); StringWriter sw = new StringWriter(); String inputLine; while ((inputLine = inFile.readLine()) != null) { sw.write(inputLine); sw.write("\n"); } sw.close(); evaluator.eval("eval(parse(text=\"" + sw.toString() + "\"))"); } catch (Exception exception) { logger.error("Could not load CDK-rJava R scripts: ", scriptLocator); logger.debug(exception); } } } Example 32 Project: dbfound File: TreeGrid.java public void executeFreemarker(Writer out) { try { Configuration cfg = FreemarkFactory.getConfig(pageContext .getServletContext()); // ??Template?? Template template = cfg.getTemplate(templateName); // ???? Map root = new HashMap(); if (id == null || "".equals(id)) { id = "TG" + UUIDUtil.getRandomString(6); } root.put("tree", this); root.put("columns", getColumns().getColumns()); ToolBar toolBar = getToolBar(); if (toolBar != null) { List buttons = toolBar.getButtons(); if (buttons != null) { root.put("buttons", buttons); } } String div = ""; Tag t = findAncestorWithClass(this, Panel.class); if (t != null && findAncestorWithClass(this, Div.class) == null) { Panel parent = (Panel) t; if (parent.contentCmp == null) { parent.contentCmp = "'" + id + "'"; } else { parent.contentCmp += ",'" + id + "'"; } try { out = new StringWriter(); parent.html += div; template.process(root, out); parent.content.append(out); } finally { out.close(); } } else { root.put("div", div); template.process(root, out); } } catch (Exception e) { LogUtil.error(e.getMessage(), e); } } Example 33 Project: MinecraftSecondScreenMod File: JSONArray.java public String toString(int indentFactor) throws JSONException { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString(); } } Example 34 Project: SOLR File: TestHarness.java public static StringBuffer makeSimpleDoc(String... fieldsAndValues) { try { StringWriter w = new StringWriter(); w.append(""); for (int i = 0; i < fieldsAndValues.length; i+=2) { XML.writeXML(w, "field", fieldsAndValues[i+1], "name", fieldsAndValues[i]); } w.append(""); return w.getBuffer(); } catch (IOException e) { throw new RuntimeException ("this should never happen with a StringWriter", e); } } Example 35 Project: r2015 File: JSONArray.java public String toString(int indentFactor) throws JSONException { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString(); } } Example 36 Project: Jorum-DSpace File: LicenseCleanup.java protected static void handleItem(Item item) throws SQLException, AuthorizeException, IOException { Bundle[] bundles = item.getBundles("CC-LICENSE"); if (bundles == null || bundles.length == 0) return; Bundle bundle = bundles[0]; Bitstream bitstream = bundle.getBitstreamByName("license_rdf"); String license_rdf = new String(copy(bitstream)); /* quickly fix xml by ripping out offensive parts */ license_rdf = license_rdf.replaceFirst("", ""); StringWriter result = new StringWriter(); try { templates.newTransformer().transform( new StreamSource(new ByteArrayInputStream(license_rdf .getBytes())), new StreamResult(result)); } catch (TransformerException e) { throw new RuntimeException(e.getMessage(), e); } StringBuffer buffer = result.getBuffer(); Bitstream newBitstream = bundle .createBitstream(new ByteArrayInputStream(buffer.toString() .getBytes())); newBitstream.setName(bitstream.getName()); newBitstream.setDescription(bitstream.getDescription()); newBitstream.setFormat(bitstream.getFormat()); newBitstream.setSource(bitstream.getSource()); newBitstream.setUserFormatDescription(bitstream .getUserFormatDescription()); newBitstream.update(); bundle.removeBitstream(bitstream); bundle.update(); } Example 37 Project: processing-shellmaker File: JSONArray.java public String format(int indentFactor) { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString(); } } Example 38 Project: gpu-garbage-collection File: OptimizingCompilerException.java public String trace(int level) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); printStackTrace(pw); int count = 0, i = 0; StringBuffer sb = sw.getBuffer(); for (; i < sb.length() && count < level + 1; i++) { if (sb.charAt(i) == '\n') { count++; } } sb.setLength(i); return sb.toString(); } Example 39 Project: dragome-sdk File: TwoColumnOutput.java public TwoColumnOutput(Writer out, int leftWidth, int rightWidth, String spacer) { if (out == null) { throw new NullPointerException("out == null"); } if (leftWidth < 1) { throw new IllegalArgumentException("leftWidth < 1"); } if (rightWidth < 1) { throw new IllegalArgumentException("rightWidth < 1"); } if (spacer == null) { throw new NullPointerException("spacer == null"); } StringWriter leftWriter = new StringWriter(1000); StringWriter rightWriter = new StringWriter(1000); this.out = out; this.leftWidth = leftWidth; this.leftBuf = leftWriter.getBuffer(); this.rightBuf = rightWriter.getBuffer(); this.leftColumn = new IndentingWriter(leftWriter, leftWidth); this.rightColumn = new IndentingWriter(rightWriter, rightWidth, spacer); } Example 40 Project: jeboorker File: JSONArray.java public String toString(int indentFactor) throws JSONException { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString(); } } Ссылка на первоисточник: http://www.programcreek.com/java-api-examples/index.php?api=java.io.StringWriter
Комментарии (0)
  • популярные
  • новые
  • старые
Для того, что бы оставить комментарий вы должны авторизироваться
У этой страницы еще нет ни одного комментария