List of usage examples for java.io StringWriter write
public void write(String str)
From source file:HtmlUtils.java
public String getTableContents(String align, Vector values, int elementCounter) throws IOException { StringWriter Cells = new StringWriter(); String contents = new String(); int vsize = values.size(); Cells.write("<TR>"); for (int i = 0; i < vsize; i++) { String value = values.elementAt(i).toString(); if (i != 0) { if (i >= elementCounter) { if (i % elementCounter == 0) { Cells.write("</TR>\n\n<TR>"); }//from www. ja va 2 s .c om } } Cells.write("<TD align=" + align + "> " + value + " </TD> \n"); } Cells.write("</TR>"); contents = Cells.toString(); Cells.flush(); Cells.close(); return contents; }
From source file:com.cybernostics.jsp2thymeleaf.api.util.AlternateFormatStrings.java
Supplier<RuntimeException> err(Map<String, Object> values) { return () -> { StringWriter message = new StringWriter(); message.write("Could not select format from candidates:"); message.write(candidateFormats.stream().map(it -> it.toString()).collect(Collectors.joining(","))); message.write('\n'); message.write("Given Attributes:"); message.write(values.keySet().stream().collect(Collectors.joining(","))); return new RuntimeException(message.toString()); };/*ww w .j a v a 2 s .c o m*/ }
From source file:isi.pasco2.poller.DifferenceHandler.java
public void endDocument() { if (!initialized) { // it is now initialized = true;// w ww . j a v a2 s .co m } else { Collection<Record> deletedRecords = CollectionUtils.subtract(currentUrlRecords, newUrlRecords); Collection<Record> newRecords = CollectionUtils.subtract(newUrlRecords, currentUrlRecords); if (deletedRecords.size() > 0 || newRecords.size() > 0) { StringWriter outWriter = new StringWriter(); outWriter.write(name + "\r\n"); for (Record rec : newRecords) { Calendar c = Calendar.getInstance(); outWriter.write("New record: (" + xsdDateFormat.format(c.getTime()) + rec.toString() + "\r\n"); } for (Record rec : deletedRecords) { outWriter.write("Deleted record: " + rec.toString() + "\r\n"); } System.out.println(outWriter.toString()); } currentUrlRecords = newUrlRecords; newUrlRecords = new Vector<Record>(); } }
From source file:com.espertech.esper.pattern.EvalAuditStateNode.java
private String toStringEvaluateFalse(EvalAuditStateNode current, String patternExpression, EvalStateNode fromNode) {/*from www . j a v a2 s . co m*/ StringWriter writer = new StringWriter(); writePatternExpr(current, patternExpression, writer); writer.write(" evaluate-false {"); writer.write(" from "); JavaClassHelper.writeInstance(writer, fromNode, false); writer.write("}"); return writer.toString(); }
From source file:com.janoz.usenet.processors.impl.NZBGetProcessor.java
private boolean isLoginResponse(InputStream stream) { StringWriter sw = new StringWriter(); int i;/*from w w w. j a v a2 s . c o m*/ try { while ((i = stream.read()) >= 0) { sw.write(i); } } catch (IOException e) { LOG.error("Error reading response.", e); throw new RetrieveException("Error reading response.", e); } return sw.toString().indexOf("Please login") > -1; }
From source file:net.officefloor.packaging.officefloor.OfficeFloorIT.java
/** * Undertakes the request./* w w w . j a v a 2 s .com*/ * * @param client * {@link HttpClient}. * @param uri * URI. * @return String content of response entity. */ private String doRequest(HttpClient client, String uri) throws Exception { HttpResponse response = client.execute(new HttpGet("http://localhost:7878/" + uri)); assertEquals("Should be successful", 200, response.getStatusLine().getStatusCode()); StringWriter buffer = new StringWriter(); Reader reader = new InputStreamReader(response.getEntity().getContent()); for (int character = reader.read(); character != -1; character = reader.read()) { buffer.write(character); } return buffer.toString(); }
From source file:edu.harvard.hul.ois.fits.tools.exiftool.Exiftool.java
private Document createXml(String execOut) throws FitsToolException { StringWriter out = new StringWriter(); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.write("\n"); out.write("<exiftool>"); out.write("\n"); out.write("<rawOutput>\n" + StringEscapeUtils.escapeXml(execOut)); out.write("</rawOutput>"); out.write("\n"); String[] lines = execOut.split("\n"); for (String line : lines) { String[] parts = line.split("\t"); String field = parts[0].trim(); if (parts.length > 1) { String value = parts[1].trim(); out.write("<" + field + ">" + StringEscapeUtils.escapeXml(value) + "</" + field + ">"); out.write("\n"); }/*from w w w . java 2s . c o m*/ } out.write("</exiftool>"); out.write("\n"); out.flush(); try { out.close(); } catch (IOException e) { throw new FitsToolException("Error closing Exiftool XML output stream", e); } Document doc = null; try { doc = saxBuilder.build(new StringReader(out.toString())); } catch (Exception e) { throw new FitsToolException("Error parsing Exiftool XML Output", e); } return doc; }
From source file:com.signavio.warehouse.business.util.jpdl4.Transition.java
public String toJpdl() throws InvalidModelException { StringWriter jpdl = new StringWriter(); jpdl.write(" <transition"); if (name != null) { jpdl.write(JsonToJpdl.transformAttribute("name", name)); }//from w w w . j a va2 s . c om if (target != null) { jpdl.write(JsonToJpdl.transformAttribute("to", target)); } else { throw new InvalidModelException("Invalid edge. Target is missing."); } if (dockers.size() > 0) { // g="120,42;120,45:0,0" String dockerString = ""; for (Docker d : dockers) { dockerString += d.toJpdl(); if (dockers.indexOf(d) == dockers.size() - 1) dockerString += ":"; else dockerString += ";"; } jpdl.write(JsonToJpdl.transformAttribute("g", dockerString)); } if (condition != null && !condition.equals("")) { jpdl.write(">\n"); jpdl.write(" <condition expr=\""); jpdl.write(StringEscapeUtils.escapeXml(condition)); jpdl.write("\" />\n"); jpdl.write(" </transition>\n"); } else { jpdl.write("/>\n"); } return jpdl.toString(); }
From source file:org.jbpm.designer.web.server.UUIDBasedRepositoryServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String profileName = Utils.getDefaultProfileName(req.getParameter("profile")); String actionParam = req.getParameter("action"); String preProcessingParam = req.getParameter("pp"); if (preProcessingParam == null) { preProcessingParam = "ReadOnlyService"; }//w w w .j a v a 2 s . co m if (actionParam != null && actionParam.equals("toXML")) { if (profile == null) { profile = _profileService.findProfile(req, profileName); } String json = req.getParameter("data"); String xml = ""; try { xml = _repository.toXML(json, profile, preProcessingParam); } catch (Exception e) { _logger.error("Error transforming to XML: " + e.getMessage()); } StringWriter output = new StringWriter(); output.write(xml); resp.setContentType("application/xml"); resp.setCharacterEncoding("UTF-8"); resp.setStatus(200); resp.getWriter().print(output.toString()); } else if (actionParam != null && actionParam.equals("checkErrors")) { String retValue = "false"; if (profile == null) { profile = _profileService.findProfile(req, profileName); } String json = req.getParameter("data"); try { String xmlOut = profile.createMarshaller().parseModel(json, preProcessingParam); String jsonIn = profile.createUnmarshaller().parseModel(xmlOut, profile, preProcessingParam); if (jsonIn == null || jsonIn.length() < 1) { retValue = "true"; } } catch (Throwable t) { retValue = "true"; _logger.error("Exception parsing process: " + t.getMessage()); } resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); resp.setStatus(200); resp.getWriter().print(retValue); } else { BufferedReader reader = req.getReader(); StringWriter reqWriter = new StringWriter(); char[] buffer = new char[4096]; int read; while ((read = reader.read(buffer)) != -1) { reqWriter.write(buffer, 0, read); } String data = reqWriter.toString(); try { JSONObject jsonObject = new JSONObject(data); String json = (String) jsonObject.get("data"); String svg = (String) jsonObject.get("svg"); String uuid = (String) jsonObject.get("uuid"); boolean autosave = jsonObject.getBoolean("savetype"); if (profile == null) { profile = _profileService.findProfile(req, profileName); } _repository.save(req, uuid, json, svg, profile, autosave); } catch (JSONException e1) { throw new ServletException(e1); } } }
From source file:org.limewire.mojito.handler.request.StatsRequestHandler.java
@Override public void request(RequestMessage message) throws IOException { StatsRequest request = (StatsRequest) message; if (!request.isSecure()) { if (LOG.isWarnEnabled()) { LOG.warn(message.getContact() + " sent us an invalid Stats Request"); }/*from w w w. j a v a 2 s .c o m*/ return; } networkStats.STATS_REQUEST.incrementStat(); StringWriter writer = new StringWriter(); switch (request.getType()) { case STATISTICS: context.getDHTStats().dump(writer, false); break; case DATABASE: writer.write(context.getDatabase().toString()); break; case ROUTETABLE: writer.write(context.getRouteTable().toString()); break; default: if (LOG.isErrorEnabled()) { LOG.error("Unknown stats request: " + request.getType()); } return; } StatsResponse response = context.getMessageHelper().createStatsResponse(message, writer.toString().getBytes("ISO-8859-1")); context.getMessageDispatcher().send(message.getContact(), response); }