@Test public void nonAbosultePath() throws MalformedURLException { URL url = ResourceLocator.findNamedResource("/tmp/a.txt"); assertThat(url, is(url("file:/tmp/a.txt"))); }
public static URL findNamedResource(final String name) { URI nameUri = URI.create(name); if (isClasspath(nameUri)) { Iterable<URL> resources = urlClassPathResource(nameUri); return firstElementOrNull(resources); } try { if (nameUri.isAbsolute()) { return nameUri.toURL(); } return new URL("file:" + name); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } }
ResourceLocator { public static URL findNamedResource(final String name) { URI nameUri = URI.create(name); if (isClasspath(nameUri)) { Iterable<URL> resources = urlClassPathResource(nameUri); return firstElementOrNull(resources); } try { if (nameUri.isAbsolute()) { return nameUri.toURL(); } return new URL("file:" + name); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } }
ResourceLocator { public static URL findNamedResource(final String name) { URI nameUri = URI.create(name); if (isClasspath(nameUri)) { Iterable<URL> resources = urlClassPathResource(nameUri); return firstElementOrNull(resources); } try { if (nameUri.isAbsolute()) { return nameUri.toURL(); } return new URL("file:" + name); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } private  ResourceLocator(); }
ResourceLocator { public static URL findNamedResource(final String name) { URI nameUri = URI.create(name); if (isClasspath(nameUri)) { Iterable<URL> resources = urlClassPathResource(nameUri); return firstElementOrNull(resources); } try { if (nameUri.isAbsolute()) { return nameUri.toURL(); } return new URL("file:" + name); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } private  ResourceLocator(); static Iterable<URL> findNamedResources(String name); static URL findNamedResource(final String name); }
ResourceLocator { public static URL findNamedResource(final String name) { URI nameUri = URI.create(name); if (isClasspath(nameUri)) { Iterable<URL> resources = urlClassPathResource(nameUri); return firstElementOrNull(resources); } try { if (nameUri.isAbsolute()) { return nameUri.toURL(); } return new URL("file:" + name); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } private  ResourceLocator(); static Iterable<URL> findNamedResources(String name); static URL findNamedResource(final String name);  }