List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:org.sonar.plugins.ideainspections.IdeaProfileExporter.java
private void appendXmlFooter(Writer writer) throws IOException { writer.append("</inspections>"); }
From source file:com.cybernostics.jsp2thymeleaf.api.expressions.ExpressionWritingVisitor.java
void append(Writer w, String toAppend) { try {//from w ww .ja v a 2 s. co m w.append(toAppend); } catch (IOException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } }
From source file:org.sonar.plugins.ideainspections.IdeaProfileExporter.java
private void appendXmlHeader(Writer writer) throws IOException { writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + // "<!-- Generated by Sonar -->\n" + // "<inspections version=\"1.0\" is_locked=\"false\">\n"); }
From source file:org.sonar.api.profiles.XMLProfileSerializer.java
private void appendRule(ActiveRule activeRule, Writer writer) throws IOException { writer.append("<rule><repositoryKey>"); writer.append(activeRule.getRepositoryKey()); writer.append("</repositoryKey><key>"); StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey()); writer.append("</key>"); if (activeRule.getSeverity() != null) { writer.append("<priority>"); writer.append(activeRule.getSeverity().name()); writer.append("</priority>"); }// www . j av a 2 s.c o m appendRuleParameters(activeRule, writer); writer.append("</rule>"); }
From source file:net.sourceforge.pmd.cpd.CSVRenderer.java
@Override public void render(Iterator<Match> matches, Writer writer) throws IOException { if (!lineCountPerFile) { writer.append("lines").append(separator); }/*from w w w . j a va 2 s . co m*/ writer.append("tokens").append(separator).append("occurrences").append(PMD.EOL); while (matches.hasNext()) { Match match = matches.next(); if (!lineCountPerFile) { writer.append(String.valueOf(match.getLineCount())).append(separator); } writer.append(String.valueOf(match.getTokenCount())).append(separator) .append(String.valueOf(match.getMarkCount())).append(separator); for (Iterator<Mark> marks = match.iterator(); marks.hasNext();) { Mark mark = marks.next(); writer.append(String.valueOf(mark.getBeginLine())).append(separator); if (lineCountPerFile) { writer.append(String.valueOf(mark.getLineCount())).append(separator); } writer.append(StringEscapeUtils.escapeCsv(mark.getFilename())); if (marks.hasNext()) { writer.append(separator); } } writer.append(PMD.EOL); } writer.flush(); }
From source file:org.apache.blur.metrics.MetricInfo.java
public void write(Writer writer) throws IOException { writer.append("{\"name\":\""); writer.append(name);/*ww w . j av a2 s. c o m*/ writer.append("\",\"type\":\""); writer.append(type); writer.append("\",\"data\":{"); writeMetricMap(writer); writer.append("}}"); }
From source file:org.sonar.api.profiles.XMLProfileSerializer.java
private void appendAlert(Alert alert, Writer writer) throws IOException { writer.append("<alert><metric>"); StringEscapeUtils.escapeXml(writer, alert.getMetric().getKey()); writer.append("</metric>"); if (alert.getPeriod() != null) { writer.append("<period>"); StringEscapeUtils.escapeXml(writer, Integer.toString(alert.getPeriod())); writer.append("</period>"); }/*from w ww.j av a 2 s .c om*/ writer.append("<operator>"); StringEscapeUtils.escapeXml(writer, alert.getOperator()); writer.append("</operator>"); writer.append("<warning>"); StringEscapeUtils.escapeXml(writer, alert.getValueWarning()); writer.append("</warning>"); writer.append("<error>"); StringEscapeUtils.escapeXml(writer, alert.getValueError()); writer.append("</error></alert>"); }
From source file:com.openedit.error.JsonErrorHandler.java
/** * @see org.jpublish.ErrorHandler#handleError(JPublishError) *///from w w w . j a va2s . c o m public boolean handleError(Throwable error, WebPageRequest context) { if (context.getResponse() != null && context.getResponse().getContentType() != null && !context.getResponse().getContentType().contains("json")) { return false; } OpenEditException exception = null; if (context != null) { try { if (!(error instanceof OpenEditException)) { exception = new OpenEditException(error); //we need the toStacktrace method } else { exception = (OpenEditException) error; } if (!context.hasRedirected() && context.getResponse() != null) { try { context.getResponse().setStatus(500); } catch (Exception ex) { //ignored log.debug("Ignored:" + ex); } } error.printStackTrace(); String pathWithError = exception.getPathWithError(); if (pathWithError == null) { pathWithError = context.getPage().getPath(); exception.setPathWithError(pathWithError); } context.putPageValue("editPath", exception.getPathWithError()); context.putPageValue("oe-exception", exception); //must be a top level thing since we create a new context PageStreamer pages = (PageStreamer) context.getPageValue(PageRequestKeys.PAGES); Writer out = context.getWriter(); out.append("{ \"reponse\": {\n"); out.append(" \"status\":\"error\","); out.append("{ \"path\":\"" + pathWithError + "\","); out.append("{ \"details\":\"" + error + "\""); out.append("\n}"); //error.printStackTrace( new PrintWriter( writer ) ); out.flush(); } catch (Exception ex) { //Do not throw an error here is it will be infinite log.error(ex); ex.printStackTrace(); try { context.getWriter().write("Check error logs: " + ex); //throw new OpenEditRuntimeException(ex); } catch (Throwable ex1) { log.error(ex1); } } return true; } return false; }
From source file:com.qcadoo.view.internal.JsonMapperHttpMessageConverter.java
@Override protected void writeInternal(final Object value, final HttpOutputMessage outputMessage) throws IOException { Writer writer = null; try {// ww w .j a v a2 s . c o m writer = new OutputStreamWriter(outputMessage.getBody(), CHARSET); writer.append(mapper.writeValueAsString(value)); writer.flush(); } finally { IOUtils.closeQuietly(writer); } }
From source file:net.sf.appstatus.web.pages.RadiatorPage.java
public void doGet(StatusWebHandler webHandler, HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException, IOException { // Setup response resp.setContentType("text/html"); resp.setCharacterEncoding("UTF-8"); // Get Health checks List<ICheckResult> results = webHandler.getAppStatus().checkAll(req.getLocale()); int status = STATUS_OK; for (ICheckResult r : results) { if (r.getCode() != ICheckResult.OK && !r.isFatal() && status == STATUS_OK) { status = STATUS_WARN;// www. j av a 2 s . c o m } if (r.getCode() != ICheckResult.OK && r.isFatal()) { status = STATUS_ERROR; break; } } String btnClass = "btn-success"; if (status == STATUS_WARN) { btnClass = "btn-warning"; } if (status == STATUS_ERROR) { btnClass = "btn-danger"; } // Get batchs status. IBatchManager manager = webHandler.getAppStatus().getBatchManager(); String batchStatus = " progress-success "; String active = StringUtils.EMPTY; int width = 0; if (manager != null) { batchStatus = manager.getErrorBatches().size() > 0 ? " progress-danger " : " progress-success "; active = manager.getRunningBatches().size() > 0 ? " progress-striped active " : ""; width = manager.getRunningBatches().size() + manager.getFinishedBatches().size() > 0 ? 100 : 0; } Writer w = resp.getWriter(); w.append("<html>"); w.append("<head>"); w.append("<meta http-equiv=\"refresh\" content=\"60;\">"); w.append("<link href=\"?resource=appstatus.css\" rel=\"stylesheet\">"); w.append("</head>"); w.append("<body style=\"background: #000; text-align: center; padding-top: 5%;\">"); w.append("<p style=\"color: #fff; font-size: 200%;\" >" + webHandler.getApplicationName() + "</p>"); w.append("<p style=\" padding-top: 10%;\"><a href=\"?p=status\" target=\"_blank\" class=\"btn btn-large " + btnClass + "\" >Status</a></p>"); w.append("<div class=\"progress " + batchStatus + active + "\" style=\"margin-top: 5%; width: 90%; margin-left: 5%; margin-right: 5%;\"> <div class=\"bar\" style=\"width: " + width + "%;\"></div></div>"); w.append("</body></html>"); }