response.setStatus(HttpServletResponse.SC_OK);
response.setContentLength((int) res.length());
// response.addHeader(ACCEPT_RANGES_HEADER, "bytes");
response.addDateHeader(LAST_MODIFIED_DATE_HEADER, res.lastModified());
OutputStream out = null;
Writer outWriter = null;
try {
out = response.getOutputStream();
} catch (IllegalStateException err) {
outWriter = response.getWriter();
} catch (IllegalArgumentException err) {
outWriter = response.getWriter();
}
byte buffer[] = new byte[4096];
int read = resStream.read(buffer);
while (read > 0) {
if (out != null) {
out.write(buffer, 0, read);
} else {
outWriter.write(new String(buffer, 0, read,
response.getCharacterEncoding()));
}
read = resStream.read(buffer);
}
resStream.close();