public static File getResourceAsFile(final String resource) { final URL url = getResourceURL(resource); if (url == null) { return null; } return new File(url.getFile()); }
@Override protected String findImage(final String className, final String[] extensions) { for(String location: locations) { for (int i = 0; i < extensions.length; i++) { String candidate = location + "/" + className + "." + extensions[i]; if (Resources.getResourceAsFile(candidate) != null) { return candidate; } } } return null; }
public static Properties getResourceAsProperties(final String resource) { final InputStream is = getResourceAsStream(resource); if (is == null) { return null; } final Properties props = new Properties(); try { props.load(is); } catch (final IOException ex) { throw new RuntimeException(ex); } finally { try { is.close(); } catch (final IOException ignore) { // ignore } } return props; }
public static Properties getResourceAsProperties(final String resource) { final InputStream is = getResourceAsStream(resource); if (is == null) { return null; } final Properties props = new Properties(); try { props.load(is); } catch (final IOException ex) { throw new RuntimeException(ex); } finally { try { is.close(); } catch (final IOException ignore) { // ignore } } return props; }
private void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { String servletPath = stripLeadingSlash(request.getServletPath()); LOG.info("request: " + servletPath); InputStream is = Resources.getResourceAsStream(servletPath); if (is != null) { IoUtils.copy(is, response.getOutputStream()); } }
public static File getResourceAsFile(final String resource) { final URL url = getResourceURL(resource); if (url == null) { return null; } return new File(url.getFile()); }
@Override protected String findImage(final String className, final String[] extensions) { for(String location: locations) { for (int i = 0; i < extensions.length; i++) { String candidate = location + "/" + className + "." + extensions[i]; if (Resources.getResourceAsFile(candidate) != null) { return candidate; } } } return null; }
private void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final String servletPath = StringUtils.stripLeadingSlash(request.getServletPath()); LOG.info("request: " + servletPath); // try to load from classpath InputStream is = Resources.getResourceAsStream(servletPath); if (is != null) { IoUtils.copy(is, response.getOutputStream()); is.close(); return; } // otherwise, try to load from filesystem is = getRealPath(request); if (is != null) { IoUtils.copy(is, response.getOutputStream()); is.close(); return; } }
final URL url = Resources.getResourceURL(path); if (url == null) { LOG.debug("not found image in resources: " + url);
private void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final String servletPath = StringUtils.stripLeadingSlash(request.getServletPath()); LOG.info("request: " + servletPath); // try to load from classpath InputStream is = Resources.getResourceAsStream(servletPath); if (is != null) { IoUtils.copy(is, response.getOutputStream()); is.close(); return; } // otherwise, try to load from filesystem is = getRealPath(request); if (is != null) { IoUtils.copy(is, response.getOutputStream()); is.close(); return; } }