List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:com.seer.datacruncher.services.HttpFileUpload.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write("Success"); out.flush();/* w w w . ja va 2 s.c o m*/ out.close(); }
From source file:com.myjeeva.spring.security.secureuri.SecureServerURI.java
/** * writes the Bad Request String in the Servlet response if condition falis * /*from w ww. j a va2 s . co m*/ * @param res a {@link javax.servlet.http.HttpServletResponse} object * @throws IOException */ private void badRequest(HttpServletResponse res) throws IOException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); pw.write(BAD_REQUEST); pw.close(); }
From source file:net.ontopia.topicmaps.nav2.servlets.AutoSuggestServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain; charset=utf-8"); String tmid = request.getParameter("tm"); if (tmid == null) throw new ServletException("Parameter tm is not given."); String term = request.getParameter("term"); if (term == null) throw new ServletException("Parameter term is not given."); TopicMapStoreIF store = TopicMaps.createStore(tmid, true); if (store instanceof net.ontopia.topicmaps.impl.basic.InMemoryTopicMapStore) term = term + '*'; try {//from w ww . jav a2 s .c om QueryProcessorIF qp = QueryUtils.getQueryProcessor(store.getTopicMap()); QueryResultIF qr = qp.execute(query, Collections.singletonMap("TERM", term)); System.out.println("query: " + query); PrintWriter w = response.getWriter(); w.write("{ results: [\n"); int count = 0; while (qr.next()) { if (count > limit) break; if (count > 0) w.write(",\n"); TopicIF topic = (TopicIF) qr.getValue(0); String desc = (String) qr.getValue(1); w.write(" { id: \""); w.write(topic.getObjectId()); w.write("\", value: \""); w.write(escape(TopicStringifiers.toString(topic))); w.write("\", info: \""); w.write((desc == null ? "" : escape(desc))); w.write("\" }"); count++; } w.write("\n] }\n"); } catch (Exception e) { throw new ServletException(e); } finally { store.close(); } }
From source file:net.sourceforge.ajaxtags.struts.BaseAjaxAction.java
@Override public ActionForward execute(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws IOException { try {//from w ww.j a v a2 s.c o m setForm(form); final String xml = AjaxActionHelper.invoke(this, request, response); if (xml != null) { // response.setCharacterEncoding(getXMLEncoding()); final PrintWriter writer = response.getWriter(); writer.write(xml); // IOUtils.closeQuietly(writer); writer.close(); if (log.isDebugEnabled()) { log.debug(xml.length() + " characters written to XML response"); } } } catch (Exception e) { final String message = getErrorMessage(e); log.error(message, e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, StringEscapeUtils.escapeHtml(message)); } setForm(null); return null; }
From source file:fr.mby.portal.coreimpl.aggregator.RenderingAggregator.java
@Override public void aggregate(final HttpServletResponse response, final IInternalRenderReply reply) { try {//w w w . ja va2 s.com reply.flushBuffer(); final PrintWriter writer = response.getWriter(); final OutputStream replyStream = reply.getBackingOutputStream(); writer.write(replyStream.toString()); replyStream.close(); } catch (final IOException e) { RenderingAggregator.LOG.error("Error while rendering IReply !", e); } }
From source file:nl.minbzk.dwr.zoeken.enricher.settings.EnricherSettingsController.java
/** * Handle a request.// w w w . jav a 2 s.c om * * @param request * @param response * @return ModelAndView */ @Override protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { PrintWriter writer = response.getWriter(); writer.write("<html>\n\t<head>\n\t\t<title>Search Enricher Settings</title>\n\t</head>\n\n\t<body>\n"); writer.write("\t<h1>Search Enricher Settings</h1>\n<hr />\n"); // Word breaking writer.write("<h2>Word breaking</h2>\n"); if (enricherSettings.getWordBreakMax() == 0 || enricherSettings.getWordBreakMin() == 0) writer.write("Disabled<br />\n"); else writer.write("Min: " + enricherSettings.getWordBreakMin() + ", Max: " + enricherSettings.getWordBreakMax() + "<br />\n"); writer.write("<br />\n"); // Additional detectors writer.write("<h2>Additional parsers and detectors for Tika</h2>\n"); if (enricherSettings.getTikaDetectors().size() > 0 || enricherSettings.getTikaParsers().size() > 0) { for (String tikaDetector : enricherSettings.getTikaDetectors()) writer.write("Detector: " + tikaDetector + "<br />\n"); for (String tikaParser : enricherSettings.getTikaParsers()) writer.write("Parser: " + tikaParser + "<br />\n"); } else writer.write("None<br />\n"); writer.write("<br />\n"); // Jobs writer.write("\t<h1>Search Enricher Jobs</h1>\n<hr />\n"); for (Entry<String, EnricherJob> entry : enricherSettings.getJobs().entrySet()) { List<Uploader> derivedUploaders = enricherService.deriveUploaders(entry.getValue()); entry.getValue().writeOut(writer, derivedUploaders); } writer.write("\t</body>\n</html>\n"); return null; }
From source file:net.sf.jasperreports.web.servlets.ViewerServlet.java
/** * *///from w w w . j a v a 2 s . c o m public void render(HttpServletRequest request, WebReportContext webReportContext, PrintWriter writer) { writer.write(getHeader(request, webReportContext)); writer.write(getBody(request, webReportContext)); writer.write(getFooter()); }
From source file:controllers.IndexServlet.java
private static void Convert(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) { response.setContentType("text/plain"); try {/* w w w.ja v a 2 s . c o m*/ String fileName = request.getParameter("filename"); String fileUri = DocumentManager.GetFileUri(fileName); String fileExt = FileUtility.GetFileExtension(fileName); FileType fileType = FileUtility.GetFileType(fileName); String internalFileExt = DocumentManager.GetInternalExtension(fileType); if (DocumentManager.GetConvertExts().contains(fileExt)) { String key = ServiceConverter.GenerateRevisionId(fileUri); Pair<Integer, String> res = ServiceConverter.GetConvertedUri(fileUri, fileExt, internalFileExt, key, true); int result = res.getKey(); String newFileUri = res.getValue(); if (result != 100) { writer.write("{ \"step\" : \"" + result + "\", \"filename\" : \"" + fileName + "\"}"); return; } String correctName = DocumentManager .GetCorrectName(FileUtility.GetFileNameWithoutExtension(fileName) + internalFileExt); URL url = new URL(newFileUri); java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection(); InputStream stream = connection.getInputStream(); if (stream == null) { throw new Exception("Stream is null"); } File convertedFile = new File(DocumentManager.StoragePath(correctName, null)); try (FileOutputStream out = new FileOutputStream(convertedFile)) { int read; final byte[] bytes = new byte[1024]; while ((read = stream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); } connection.disconnect(); //remove source file ? //File sourceFile = new File(DocumentManager.StoragePath(fileName, null)); //sourceFile.delete(); fileName = correctName; } writer.write("{ \"filename\" : \"" + fileName + "\"}"); } catch (Exception ex) { writer.write("{ \"error\": \"" + ex.getMessage() + "\"}"); } }
From source file:de.undercouch.gradle.tasks.download.RedirectTest.java
@Override protected Handler[] makeHandlers() throws IOException { ContextHandler redirectHandler = new ContextHandler("/" + REDIRECT) { @Override/* w ww .j a va2 s . c om*/ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { if (redirects > 0) { redirects--; if (circular) { response.sendRedirect("/" + REDIRECT); } else { response.sendRedirect("/" + REDIRECT + "?r=" + redirects); } } else { response.setStatus(200); PrintWriter rw = response.getWriter(); rw.write("r: " + redirects); rw.close(); } } }; return new Handler[] { redirectHandler }; }
From source file:com.eternity.common.communication.servlet.SyncJSONDispatch.java
protected void doRequest(HttpServletRequest req, HttpServletResponse resp, InputStream data) throws ServletException, IOException { String contentType = req.getContentType(); String charset = req.getCharacterEncoding(); String acceptsHeader = req.getHeader("Accept"); Encoder encoder = null;//w w w. j a v a 2s. co m Decoder decoder = ProtocolHandlers.getHandlers().getDecoder(contentType); if (charset == null) { charset = "UTF-8"; } if (decoder == null) { resp.setStatus(400); PrintWriter p = resp.getWriter(); p.write("Unacceptable Content-Type!"); return; } if (acceptsHeader != null) { String accepts[] = acceptsHeader.split(","); for (String accept : accepts) { encoder = ProtocolHandlers.getHandlers().getEncoder(accept.trim()); if (encoder != null) break; } } else { encoder = ProtocolHandlers.getHandlers().getEncoder(contentType); } if (encoder == null) { resp.setStatus(400); PrintWriter p = resp.getWriter(); p.write("Unacceptable or missing ACCEPT header!"); return; } String jsonMessage = req.getParameter(Parameter.jsonMessage.toString()); Message message = (Message) decoder.decode(ByteBuffer.wrap(jsonMessage.getBytes(charset)), Message.class); message.encoding = contentType; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); if (data != null) IOUtils.copy(data, bytes); message.body = ByteBuffer.wrap(bytes.toByteArray()); Object result = MessageConsumer.dispatchMessage(message, null, hostName); resp.getOutputStream().write(encoder.encode(result).array()); }