List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:IOUtils.java
/** * Writes chars from a <code>StringBuffer</code> to a <code>Writer</code>. * /* w w w .ja v a2 s .co m*/ * @param data the <code>StringBuffer</code> to write, null ignored * @param output the <code>Writer</code> to write to * @throws NullPointerException if output is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static void write(StringBuffer data, Writer output) throws IOException { if (data != null) { output.write(data.toString()); } }
From source file:de.terrestris.shogun.security.ShogunAuthProcessingFilter.java
/** * React on unsuccessful authentication. * We again intercept the response and return a JSON object with a flag indicating unsuccessful login. * * @see WebContent/client/login.js/*from www . j a v a 2s . c o m*/ */ @Override protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException { super.unsuccessfulAuthentication(request, response, failed); HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); Writer out = responseWrapper.getWriter(); out.write("{success:false}"); out.close(); }
From source file:com.ewcms.component.counter.web.CounterServlet.java
private void reponseCount(HttpServletRequest request, HttpServletResponse response, final String encoding, final int count) throws IOException { initResponseHeader(response, encoding); String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME); String value;// w w w . j a va 2 s . c o m if (callback == null) { value = "alert('?');"; } else { value = String.format("%s(\"%d\");", callback, count); } Writer writer = response.getWriter(); writer.write(value); writer.flush(); }
From source file:com.laxser.blitz.web.portal.impl.NestedWindowRender.java
private void writeExceptionAsContent(Writer out, WindowImpl window) throws IOException { out.write(window.getPath()); out.write("<br>"); out.write(String.valueOf(window.getStatusCode())); if (window.getStatusMessage() != null) { out.write(" "); out.write(window.getStatusMessage()); }/* w ww . j a v a2 s . com*/ out.write("<br>"); out.write("<pre>"); Throwable ex = window.getThrowable(); PrintWriter printWriter = new PrintWriter(out); ex.printStackTrace(printWriter); out.write("</pre>"); }
From source file:com.careerly.common.support.resolver.ControllerExceptionResolver.java
/** * @param request/*from ww w .ja v a 2s. c o m*/ * @param response * @param handler * @return */ private void resolveDataException(HttpServletRequest request, HttpServletResponse response, Object handler, StandardJsonObject errorJsonObject) { try { String data = null; String callbackValue = request.getParameter("callback"); if (StringUtils.isNotBlank(callbackValue)) { StringBuilder builder = new StringBuilder(); builder.append(StringEscapeUtils.escapeHtml(callbackValue)).append("("); builder.append(JsonUtils.marshalToString(errorJsonObject)); builder.append(")"); data = builder.toString(); } else { data = JsonUtils.marshalToString(errorJsonObject); } response.setContentType("application/json;charset=UTF-8"); Writer writer = response.getWriter(); writer.write(data); writer.close(); } catch (IOException e) { ControllerExceptionResolver.logger.error("ERROR ## write message happened error, the trace ", e); } }
From source file:org.clear.server.view.PlainTextView.java
@Override protected void renderMergedOutputModel(Map<String, Object> arg0, HttpServletRequest arg1, HttpServletResponse arg2) throws Exception { Writer out = arg2.getWriter(); for (String key : arg0.keySet()) { String value = arg0.get(key).toString(); out.write(value); }/*from w ww .j a v a2 s .co m*/ }
From source file:net.myrrix.web.servlets.EstimateForAnonymousServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;/*from w w w . j av a 2 s . c om*/ } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); long toItemID; Pair<long[], float[]> itemIDsAndValue; try { toItemID = Long.parseLong(pathComponents.next()); itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } catch (NumberFormatException nfe) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString()); return; } if (itemIDsAndValue.getFirst().length == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items"); return; } long[] itemIDs = itemIDsAndValue.getFirst(); float[] values = itemIDsAndValue.getSecond(); MyrrixRecommender recommender = getRecommender(); try { float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values); Writer out = response.getWriter(); out.write(Float.toString(estimate)); out.write('\n'); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } }
From source file:com.sloshydog.timely.HtmlReportGenerator.java
public void createReportFor(MavenSession mavenSession, List<EventRecorder.TimedEvent> timedEvents) { Writer writer = null; try {//w w w . j a v a2 s . co m writer = getReportWriterFactory().createWriter(mavenSession); writer.write(getHtmlFactory().build(timedEvents)); } catch (IOException e) { throw new RuntimeException("Unable to generate report for Timely.", e); } finally { IOUtils.closeQuietly(writer); } }
From source file:com.cognifide.aet.rest.XUnitServlet.java
private InputStream generateXML(Testsuites xUnitModel) throws JAXBException, IOException { Writer writer = new StringWriter(); writer.write(XML_HEADER); prepareJaxbMarshaller().marshal(xUnitModel, writer); return IOUtils.toInputStream(writer.toString(), Charsets.UTF_8); }
From source file:io.aos.t4f.hadoop.mapred.WordCountTest.java
private void createTextInputFile() throws IOException { OutputStream os = getFileSystem().create(new Path(input, "wordcount")); Writer wr = new OutputStreamWriter(os); wr.write("b a a\n"); wr.close();//from ww w. ja v a 2s. c o m }