code: public static void handleCacheableResponse(HttpServletRequest request,
  			HttpServletResponse response, byte[] data, String contentType)
  			throws IOException {
  		String ifNoneMatch = request.getHeader("If-None-Match");
  		String etag = "\"0" + DigestUtils.md5DigestAsHex(data) + "\"";
  
  		addCacheHeaders(response, etag, 6);
  
  		if (etag.equals(ifNoneMatch)) {
  			response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
  			return;
  		}
  
  		response.setContentType(contentType);
  		response.setContentLength(data.length);
  
  		@SuppressWarnings("resource")
  		ServletOutputStream out = response.getOutputStream();
  		out.write(data);
  		out.flush();
  	}
docs: Checks etag and sends back HTTP status 304 if not modified. If modified sets
  content type and content length, adds cache headers (
  {@link #addCacheHeaders(HttpServletResponse, String, Integer)}), writes the data
  into the {@link HttpServletResponse#getOutputStream()} and flushes it.
  
  @param request the HTTP servlet request
  @param response the HTTP servlet response
  @param data the response data
  @param contentType the content type of the data (i.e.
  "application/javascript;charset=utf-8")
  @throws IOException