public static void handleSendFile(final Request request) {
final Object f = request.getAttribute(Request.SEND_FILE_ATTR);
if (f != null) {
final Response response = request.getResponse();
if (response.isCommitted()) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING,
"SendFile can't be performed,"
+ "because response headers are committed");
}
return;
}
final File file = (File) f;
Long offset = (Long) request.getAttribute(Request.SEND_FILE_START_OFFSET_ATTR);
Long len = (Long) request.getAttribute(Request.SEND_FILE_WRITE_LEN_ATTR);
if (offset == null) {
offset = 0L;
}
if (len == null) {
len = file.length();
}
// let the sendfile() method suspend/resume the response.
response.getOutputBuffer().sendfile(file, offset, len, null);
}
}