private void loadCompleteContent(final HttpServletRequestImpl request, final HttpServletResponseImpl response, final File file) throws IOException { response.setContentType(mimeTypeMapping.getMimeTypeByExtension(FileUtilities.getExtension(file.getName()))); response.setStatus(HttpServletResponse.STATUS_OK); response.setContentLength(file.length()); response.getHeaders().setHeader(Headers.HEADER_ACCEPT_RANGES, "bytes"); response.flushHeaders(); if (!request.getMethod().equals(HttpServletRequest.METHOD_HEAD)) { InputStream fileInputStream = new FileInputStream(file); try { response.serveStream(fileInputStream); } finally { IOUtilities.closeSilently(fileInputStream); } } response.flush(); }
if (ranges.size() == 1) { response.setContentLength(rangeLength); response.setContentType(contentType); } else { boundary = StringUtilities.generateRandom(); contentType, file.length()) + rangeLength); response.setContentType("multipart/byteranges; boundary=" + boundary);
/** * Terminates servlet. Sets all necessary headers, flushes content. * * @param request * @param response * @throws IOException */ private void terminate(final HttpServletRequestImpl request, final HttpServletResponseImpl response) throws IOException { freeUploadedUnprocessedFiles(request.getUploadedFiles()); HttpSessionImpl session = (HttpSessionImpl) request.getSession(false); if (session != null) { try { ((ServletContextImpl) request.getServletContext()).handleSession(session, response); } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to persist session", e); } } if (!response.isCommitted()) { if (response.getContentType() == null) { response.setContentType(DEFAULT_RESPONSE_CONTENT_TYPE); } response.getHeaders().setHeader(Headers.HEADER_CACHE_CONTROL, HEADER_VALUE_NO_CACHE); response.getHeaders().setHeader(Headers.HEADER_PRAGMA, HEADER_VALUE_NO_CACHE); } response.flush(); }