MCPcopy Create free account
hub / github.com/apache/tomcat / close

Method close

java/org/apache/catalina/connector/OutputBuffer.java:208–245  ·  view source on GitHub ↗

Close the output buffer. This tries to calculate the response size if the response has not been committed yet. @throws IOException An underlying IOException occurred

()

Source from the content-addressed store, hash-verified

206 * @throws IOException An underlying IOException occurred
207 */
208 @Override
209 public void close() throws IOException {
210
211 if (closed) {
212 return;
213 }
214 if (suspended) {
215 return;
216 }
217
218 // If there are chars, flush all of them to the byte buffer now as bytes are used to
219 // calculate the content-length (if everything fits into the byte buffer, of course).
220 if (cb.remaining() > 0) {
221 flushCharBuffer();
222 }
223
224 // Content length can be calculated if:
225 // - the response has not been committed
226 // AND
227 // - the content length has not been explicitly set
228 // AND
229 // - some content has been written OR this is NOT a HEAD request
230 if (!coyoteResponse.isCommitted() && coyoteResponse.getContentLengthLong() == -1 &&
231 (bb.remaining() > 0 || !Method.HEAD.equals(coyoteResponse.getRequest().getMethod()))) {
232 coyoteResponse.setContentLength(bb.remaining());
233 }
234
235 doFlush(coyoteResponse.getStatus() == HttpServletResponse.SC_SWITCHING_PROTOCOLS);
236 closed = true;
237
238 // The request should have been completely read by the time the response
239 // is closed. Further reads of the input a) are pointless and b) really
240 // confuse AJP (bug 50189) so close the input buffer to prevent them.
241 Request req = (Request) coyoteResponse.getRequest().getNote(CoyoteAdapter.ADAPTER_NOTES);
242 req.inputBuffer.close();
243
244 coyoteResponse.action(ActionCode.CLOSE, null);
245 }
246
247
248 /**

Callers 1

updateBytesWrittenMethod · 0.95

Calls 13

flushCharBufferMethod · 0.95
doFlushMethod · 0.95
remainingMethod · 0.80
isCommittedMethod · 0.65
getContentLengthLongMethod · 0.65
equalsMethod · 0.65
getMethodMethod · 0.65
getRequestMethod · 0.65
setContentLengthMethod · 0.65
getStatusMethod · 0.65
getNoteMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected