Java Code Examples for javax.servlet.http.HttpServletResponse#getBufferSize()
The following examples show how to use
javax.servlet.http.HttpServletResponse#getBufferSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletHelper.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Sends content by copying all bytes from the input stream to the response setting the preferred buffer * size. At the end, it flushes response buffer. Passed in {@link InputStream} is fully consumed and closed. * The passed in {@link HttpServletResponse} after this call returns is committed and flushed. */ public static void sendContent(final InputStream input, final HttpServletResponse response) throws IOException { int bufferSize = BUFFER_SIZE; if (bufferSize < 1) { // if no user override, ask container for bufferSize bufferSize = response.getBufferSize(); if (bufferSize < 1) { bufferSize = 8192; response.setBufferSize(bufferSize); } } else { // user override present, tell container what buffer size we'd like response.setBufferSize(bufferSize); } try (final InputStream from = input; final OutputStream to = response.getOutputStream()) { final byte[] buf = new byte[bufferSize]; while (true) { int r = from.read(buf); if (r == -1) { break; } to.write(buf, 0, r); } response.flushBuffer(); } }
Example 2
Source File: RequestLabelsHelper.java From cloud-trace-java with Apache License 2.0 | 5 votes |
/** * Adds span label annotations based on the given HTTP servlet response to the given labels * builder. * * @param response the http servlet response used to generate the span label annotations. * @param labelsBuilder the labels builder to add span label annotations to. */ public static void addResponseLabels(HttpServletResponse response, Labels.Builder labelsBuilder) { // Add "/http/status_code" to Integer.toString(response.getStatus()), if // GAE supports 3.0. if (response.getBufferSize() > 0) { labelsBuilder.add( "/http/response/size", Integer.toString(response.getBufferSize())); } }
Example 3
Source File: ETagResponseWrapper.java From jease with GNU General Public License v3.0 | 4 votes |
public ETagResponseWrapper(HttpServletResponse response) { super(response); capture = new ByteArrayOutputStream(response.getBufferSize()); }