code: private static URL getUrlForResourceAsStream(final ExternalContext externalContext, String path)
              throws MalformedURLException
      {
          URLStreamHandler handler = new URLStreamHandler()
          {
              protected URLConnection openConnection(URL u) throws IOException
              {
                  final String file = u.getFile();
                  return new URLConnection(u)
                  {
                      public void connect() throws IOException
                      {
                      }
  
                      public InputStream getInputStream() throws IOException
                      {
                          if (log.isLoggable(Level.FINE))
                          {
                              log.fine("Opening internal url to " + file);
                          }
                          Object ctx = externalContext.getContext();
                          // Or maybe fetch the external context afresh ?
                          // Object ctx =
                          // FacesContext.getCurrentInstance().getExternalContext().getContext();
  
                          if (ctx instanceof ServletContext)
                          {
                              ServletContext servletContext = (ServletContext) ctx;
                              InputStream stream = servletContext.getResourceAsStream(file);
                              if (stream == null)
                              {
                                  throw new FileNotFoundException("Cannot open resource " + file);
                              }
                              return stream;
                          }
                          else
                          {
                              throw new IOException("Cannot open resource for an context of "
                                      + (ctx != null ? ctx.getClass() : null));
                          }
                      }
                  };
              }
          };
          return new URL("internal", null, 0, path, handler);
      }
docs: ServletContext.getResourceAsStream()