code: protected void writeStaticResourceResponse(
          HttpServletRequest request,
          HttpServletResponse response,
          URL resourceUrl)
      throws IOException {
  
          URLConnection connection = null;
          InputStream is = null;
          String urlStr = resourceUrl.toExternalForm();
          try {
              if (allowServePrecompressedResource(request, urlStr)) {
                  // try to serve a precompressed version if available
                  try {
                      connection = new URL(urlStr + ".gz").openConnection();
                      is = connection.getInputStream();
                      // set gzip headers
                      response.setHeader("Content-Encoding", "gzip");
                  } catch (Exception e) {
                      LOG.debug("Unexpected exception looking for gzipped version of resource " + urlStr, e);
                  }
              }
              if (is == null) {
                  // precompressed resource not available, get non compressed
                  connection = resourceUrl.openConnection();
                  try {
                      is = connection.getInputStream();
                  } catch (FileNotFoundException e) {
                      LOG.debug(e.getMessage(), e);
                      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
                      return;
                  }
              }
  
              try {
                  @SuppressWarnings("null")
                  int length = connection.getContentLength();
                  if (length >= 0) {
                      response.setContentLength(length);
                  }
              } catch (Throwable e) {
                  LOG.debug(e.getMessage(), e);
                  // This can be ignored, content length header is not required.
                  // Need to close the input stream because of
                  // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700 to
                  // prevent it from hanging, but that is done below.
              }
  
              streamContent(response, is);
          } finally {
              if (is != null) {
                  is.close();
              }
          }
      }
docs: Writes the contents of the given resourceUrl in the response. Can be
  overridden to add/modify response headers and similar.<p>
  
  @param request the request for the resource
  @param response the response
  @param resourceUrl the url to send
  
  @throws IOException in case writing the response fails