List of usage examples for javax.servlet ServletOutputStream print
public void print(double d) throws IOException
double
value to the client, with no carriage return-line feed (CRLF) at the end. From source file:org.myjerry.util.ResponseUtil.java
public static final ModelAndView sendFileToDownload(HttpServletResponse response, String fileToDownload, String fileName, String contentType, boolean isHttp11) throws IOException { response.reset();//from ww w . j a v a2 s . c o m setNoCache(response, isHttp11); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setContentType(contentType); ServletOutputStream out; out = response.getOutputStream(); out.print(fileToDownload); out.flush(); out.close(); return null; }
From source file:com.soolr.core.web.Servlets.java
public static void output(HttpServletResponse response, String contentType, Object content) throws IOException { ServletOutputStream output = response.getOutputStream(); try {//from w w w . j a v a 2 s . c o m response.setContentType(contentType); if (content instanceof byte[]) { byte[] temp = (byte[]) content; output.write(temp); } else if (content instanceof String) { output.print(String.valueOf(content)); } } finally { output.flush(); output.close(); } }
From source file:org.apache.jena.fuseki.servlets.ResponseJson.java
private static void jsonOutput(HttpAction action, final Iterator<JsonObject> jsonItems) { OutputContent proc = new OutputContent() { @Override//from www. j a v a 2 s. com public void output(ServletOutputStream out) { if (jsonItems != null) ResultSetFormatter.output(out, jsonItems); } }; try { String callback = ResponseOps.paramCallback(action.request); ServletOutputStream out = action.response.getOutputStream(); if (callback != null) { callback = StringUtils.replaceChars(callback, "\r", ""); callback = StringUtils.replaceChars(callback, "\n", ""); out.print(callback); out.println("("); } output(action, "application/json", WebContent.charsetUTF8, proc); if (callback != null) out.println(")"); } catch (IOException ex) { ServletOps.errorOccurred(ex); } }
From source file:org.wings.session.SmartURLsFilter.java
private static void encode(ByteArrayOutputStream bytes, ServletOutputStream out) throws IOException { String regex = "(href|src|action) *= *\"([^\"]*)\""; SmartURLsFilter smartURLsFilter = new SmartURLsFilter(); String replacement = smartURLsFilter.parameterSeparator + "$2" + smartURLsFilter.nameValueSeparator + "$4"; smartURLsFilter.encodePattern = Pattern .compile("(" + "\\?|&" + ")([a-zA-Z0-9%+.-[*]_]*)" + "(" + "=" + ")([a-zA-Z0-9%+.-[*]_=/]*)"); CharBuffer chars = CharBuffer.wrap(bytes.toString()); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(chars); int pos = 0;/*from ww w . ja v a2 s. c o m*/ while (matcher.find()) { out.print(chars.subSequence(pos, matcher.start()).toString()); pos = matcher.end(); Matcher matcher2 = smartURLsFilter.encodePattern.matcher(matcher.group(2)); String group2 = matcher2.replaceAll(replacement); out.print(matcher.group(1) + "=\"" + group2 + "\""); } out.print(chars.subSequence(pos, bytes.size()).toString()); }
From source file:org.apache.jena.fuseki.servlets.ResponseResultSet.java
private static void jsonOutput(HttpAction action, String contentType, final ResultSet resultSet, final Boolean booleanResult) { OutputContent proc = new OutputContent() { @Override//from w w w .j a v a 2 s. co m public void output(ServletOutputStream out) { if (resultSet != null) ResultSetFormatter.outputAsJSON(out, resultSet); if (booleanResult != null) ResultSetFormatter.outputAsJSON(out, booleanResult); } }; try { String callback = ResponseOps.paramCallback(action.request); ServletOutputStream out = action.response.getOutputStream(); if (callback != null) { callback = StringUtils.replaceChars(callback, "\r", ""); callback = StringUtils.replaceChars(callback, "\n", ""); out.print(callback); out.println("("); } output(action, contentType, WebContent.charsetUTF8, proc); if (callback != null) out.println(")"); } catch (IOException ex) { errorOccurred(ex); } }
From source file:simplestorage.hashtable.JsonView.java
@Override protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/plain"); response.setHeader("Cache-Control", "no-cache"); String json = model.get("responseJson").toString(); ServletOutputStream out = response.getOutputStream(); out.print(json); out.close();//from w ww . j a v a2 s . co m }
From source file:it.cilea.osd.jdyna.web.controller.AutocompleteUsersView.java
protected void renderMergedOutputModel(Map model, HttpServletRequest httpServletRequest, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); List<DTOAutocomplete> users = (List<DTOAutocomplete>) model.get("result"); String xml = new AjaxXmlBuilder().addItems(users, "display", "id", true).toString(); ServletOutputStream out = response.getOutputStream(); out.print(xml); out.close();// w w w . jav a 2s . co m }
From source file:org.onebusaway.nyc.vehicle_tracking.webapp.servlets.VehicleLocationCollectionServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { BufferedReader reader = req.getReader(); StringBuffer out = new StringBuffer(); char[] buf = new char[4096]; while (true) { int n = reader.read(buf); if (n == -1) { break; }//from w w w.j a v a 2 s . com out.append(new String(buf, 0, n)); } String body = out.toString(); Siri siri = (Siri) _xstream.fromXML(body); _vehicleLocationService.handleVehicleLocation(siri, body); resp.setStatus(200); resp.setContentType("text/html;charset=UTF-8"); ServletOutputStream writer = resp.getOutputStream(); writer.print("ok"); writer.close(); }
From source file:org.reallysqs.server.views.ReceivedMessagesResponseView.java
@SuppressWarnings("unchecked") @Override//from w ww .j a v a2 s . c om protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); List<Message> messages = (List<Message>) model.get("messages"); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); if (messages != null) { for (Message message : messages) { outputStream.print("<Message><MessageId>"); outputStream.print(message.getUuid()); outputStream.print("</MessageId><MessageBody>"); outputStream.print(message.getContent()); outputStream.print("</MessageBody></Message>"); } } outputStream.print(epilogue); }
From source file:org.reallysqs.server.views.QueueListView.java
@SuppressWarnings("unchecked") @Override/* w w w . j a va 2 s . c om*/ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); Map<String, Queue> queues = (Map<String, Queue>) model.get("queues"); Collection<Queue> queueList = queues.values(); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); for (Queue queue : queueList) { outputStream.print("<QueueUrl>"); outputStream.print("http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName()); outputStream.print("</QueueUrl>"); } outputStream.print(epilogue); }