List of usage examples for javax.servlet.http HttpServletResponse setBufferSize
public void setBufferSize(int size);
From source file:net.mindengine.oculus.frontend.web.controllers.display.FileDisplayController.java
public static void showFile(HttpServletResponse response, String path, String fileName, String contentType) throws IOException { File file = new File(path); response.setBufferSize((int) file.length()); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); response.setContentType(contentType); response.setContentLength((int) file.length()); byte[] bytes = new byte[(int) file.length()]; FileInputStream fis = new FileInputStream(file); fis.read(bytes);//from www . j av a 2 s.co m fis.close(); FileCopyUtils.copy(bytes, response.getOutputStream()); }
From source file:fiftyone.mobile.detection.webapp.JavascriptProvider.java
static void sendJavaScript(HttpServletRequest request, HttpServletResponse response, Dataset dataSet, StringBuilder javascript) throws IOException { response.reset();/* w ww .j a va 2 s. c om*/ response.setContentType("application/x-javascript"); response.setCharacterEncoding("UTF-8"); response.setHeader("Vary", "User-Agent"); response.setHeader("Cache-Control", "public"); response.setHeader("Expires", dataSet.nextUpdate.toString()); response.setHeader("Last-Modified", dataSet.published.toString()); try { response.setHeader("ETag", eTagHash(dataSet, request)); } catch (Exception ex) { // The response doesn't support eTags. Nothing we can do. } response.setBufferSize(DEFAULT_BUFFER_SIZE); response.setHeader("Content-Length", Integer.toString(javascript.length())); response.getOutputStream().println(javascript.toString()); response.getOutputStream().flush(); response.getOutputStream().close(); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setBufferSize(8 * 1024); // 8K buffer res.setContentType("text/html"); PrintWriter out = res.getWriter(); int size = res.getBufferSize(); // returns 8096 or greater // Record the default size, in the log log("The default buffer size is " + size); out.println("The client won't see this"); res.reset();//from ww w . ja v a 2 s .c om out.println("And this won't be seen if sendError() is called"); if (req.getParameter("important_parameter") == null) { res.sendError(res.SC_BAD_REQUEST, "important_parameter needed"); } }
From source file:Buffering.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setBufferSize(8 * 1024); // 8K res.setContentType("text/html"); PrintWriter out = res.getWriter(); int size = res.getBufferSize(); // returns 8096 or greater log("The default buffer size is " + size); out.println("The client won't see this"); res.reset();//from ww w. j ava 2 s. c o m out.println("Nor will the client see this!"); res.reset(); out.println("And this won't be seen if sendError() is called"); if (req.getParameter("param") == null) { res.sendError(res.SC_BAD_REQUEST, "param needed"); } }
From source file:com.javiermoreno.springboot.mvc.minimal.httpd.PingController.java
@RequestMapping(value = "/long", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK)/*from w ww .j a va 2 s.c o m*/ void longPing(HttpServletResponse response) throws IOException, InterruptedException { response.setBufferSize(0); PrintWriter out = response.getWriter(); out.println(); out.flush(); for (int i = 0; i < 60 * 5; i++) { out.format("Current server time: %s.\r\n", new Date()); out.flush(); Thread.sleep(1000); } }
From source file:nl.tue.gale.ae.JSONServlet.java
private void reply(String s, HttpServletResponse resp) throws IOException { resp.setBufferSize(8192); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream())); bw.write(s);/*from w w w .j ava 2 s . c o m*/ bw.close(); }
From source file:org.gwtwidgets.server.filters.ResponseHeaderFilter.java
private void addHeaders(HttpServletRequest request, HttpServletResponse response) { response.setBufferSize(0); String query = request.getRequestURI(); Matcher urlMatcher = urlPattern.matcher(query); if (!urlMatcher.matches()) return;// w ww . j a v a 2 s .c o m for (int i = 0; i < headers.length; i++) response.setHeader(headers[i], values[i]); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); // Ask for a 16K byte response buffer; do not set the content length res.setBufferSize(16 * 1024); PrintWriter out = res.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>"); out.println("<BODY>"); out.println("<BIG>Less than 16K of response body</BIG>"); out.println("</BODY></HTML>"); }
From source file:com.cloudseal.spring.client.namespace.CloudSealLogoutImageFilter.java
public void writeContent(HttpServletResponse response, String contentType, InputStream content) throws IOException { response.setBufferSize(DEFAULT_BUFFER_SIZE); response.setContentType(contentType); BufferedInputStream input = null; BufferedOutputStream output = null; try {// www.j av a 2 s.co m input = new BufferedInputStream(content, DEFAULT_BUFFER_SIZE); output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE); byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int length = 0; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } } finally { output.close(); input.close(); } }
From source file:net.siegmar.japtproxy.JaptProxyServlet.java
/** * Check the requested data and forward the request to internal sender. * * @param req the HttpServletRequest object * @param res the HttpServletResponse object * @throws ServletException {@inheritDoc} * @throws IOException {@inheritDoc} *//*from w w w .ja v a 2s .co m*/ @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { res.setBufferSize(Util.DEFAULT_BUFFER_SIZE); MDC.put("REQUEST_ID", DigestUtils.md5Hex(Long.toString(System.currentTimeMillis()))); LOG.debug("Incoming request from IP '{}', " + "User-Agent '{}'", req.getRemoteAddr(), req.getHeader(HttpHeaderConstants.USER_AGENT)); if (LOG.isDebugEnabled()) { logHeader(req); } try { japtProxy.handleRequest(req, res); } catch (final InvalidRequestException e) { LOG.warn(e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request"); return; } catch (final UnknownBackendException e) { LOG.info(e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown backend"); return; } catch (final ResourceUnavailableException e) { LOG.debug(e.getMessage(), e); res.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (final HandlingException e) { LOG.error("HandlingException", e); res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } finally { MDC.clear(); } res.flushBuffer(); }