@Override public URL getURL() throws IOException { return this.encoded.getURL(); }
@Override public URL getURL() throws IOException { return this.gzipped.getURL(); }
@Override public URL getURL() throws IOException { return this.gzipped.getURL(); }
@Override public URL getURL() throws IOException { return this.original.getURL(); }
@Override public URL getURL() throws IOException { return this.encoded.getURL(); }
@Override public URL getURL() throws IOException { return this.delegate.getURL(); }
@Override public URL getURL() throws IOException { return this.original.getURL(); }
/** * Set the WSDL document URL as a {@link Resource}. * @since 3.2 */ public void setWsdlDocumentResource(Resource wsdlDocumentResource) throws IOException { Assert.notNull(wsdlDocumentResource, "WSDL Resource must not be null"); this.wsdlDocumentUrl = wsdlDocumentResource.getURL(); }
@Override protected Resource[] createInstance() throws Exception { List<Resource> scripts = new ArrayList<>(); for (String location : this.locations) { List<Resource> resources = new ArrayList<>( Arrays.asList(this.resourcePatternResolver.getResources(location))); resources.sort((r1, r2) -> { try { return r1.getURL().toString().compareTo(r2.getURL().toString()); } catch (IOException ex) { return 0; } }); scripts.addAll(resources); } return scripts.toArray(new Resource[0]); }
@Override @Nullable public String getAsText() { Resource value = (Resource) getValue(); try { // Try to determine URL for resource. return (value != null ? value.getURL().toExternalForm() : ""); } catch (IOException ex) { // Couldn't determine resource URL - return null to indicate // that there is no appropriate text representation. return null; } }
@Override @Nullable public URL getResource(String path) throws MalformedURLException { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getURL(); } catch (MalformedURLException ex) { throw ex; } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not get URL for " + resource, ex); } return null; } }
@Override @Nullable public URL getResource(String name) { Assert.state(this.resourceLoader != null, "ResourceLoaderClassLoadHelper not initialized"); Resource resource = this.resourceLoader.getResource(name); if (resource.exists()) { try { return resource.getURL(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not load " + resource); } return null; } } else { return getClassLoader().getResource(name); } }
@Override public void setAsText(String text) throws IllegalArgumentException { this.resourceEditor.setAsText(text); Resource resource = (Resource) this.resourceEditor.getValue(); try { setValue(resource != null ? new InputSource(resource.getURL().toString()) : null); } catch (IOException ex) { throw new IllegalArgumentException( "Could not retrieve URL for " + resource + ": " + ex.getMessage()); } }
@Override public void setAsText(String text) throws IllegalArgumentException { this.resourceEditor.setAsText(text); Resource resource = (Resource) this.resourceEditor.getValue(); try { setValue(resource != null ? resource.getURL() : null); } catch (IOException ex) { throw new IllegalArgumentException("Could not retrieve URL for " + resource + ": " + ex.getMessage()); } }
/** * Create a parent ClassLoader for Groovy to use as parent ClassLoader * when loading and compiling templates. */ protected ClassLoader createTemplateClassLoader() throws IOException { String[] paths = StringUtils.commaDelimitedListToStringArray(getResourceLoaderPath()); List<URL> urls = new ArrayList<>(); for (String path : paths) { Resource[] resources = getApplicationContext().getResources(path); if (resources.length > 0) { for (Resource resource : resources) { if (resource.exists()) { urls.add(resource.getURL()); } } } } ClassLoader classLoader = getApplicationContext().getClassLoader(); Assert.state(classLoader != null, "No ClassLoader"); return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[0]), classLoader) : classLoader); }
/** * Create a test {@link ClassLoader} that creates an index with the * specified {@link Resource} instances * @param classLoader the classloader to use for all other operations * @return a test {@link ClassLoader} with an index built based on the * specified resources. */ public static ClassLoader index(ClassLoader classLoader, Resource... resources) { return new CandidateComponentsTestClassLoader(classLoader, Collections.enumeration(Stream.of(resources).map(r -> { try { return r.getURL(); } catch (Exception ex) { throw new IllegalArgumentException("Invalid resource " + r, ex); } }).collect(Collectors.toList()))); }
/** * Try to determine the persistence unit root URL based on the given * "defaultPersistenceUnitRootLocation". * @return the persistence unit root URL to pass to the JPA PersistenceProvider * @see #setDefaultPersistenceUnitRootLocation */ @Nullable private URL determineDefaultPersistenceUnitRootUrl() { if (this.defaultPersistenceUnitRootLocation == null) { return null; } try { URL url = this.resourcePatternResolver.getResource(this.defaultPersistenceUnitRootLocation).getURL(); return (ResourceUtils.isJarURL(url) ? ResourceUtils.extractJarFileURL(url) : url); } catch (IOException ex) { throw new PersistenceException("Unable to resolve persistence unit root URL", ex); } }
@Override @Nullable public URL getResource(String path) throws MalformedURLException { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getURL(); } catch (MalformedURLException ex) { throw ex; } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not get URL for " + resource, ex); } return null; } }
private void doTestResource(Resource resource) throws IOException { assertEquals("Resource.class", resource.getFilename()); assertTrue(resource.getURL().getFile().endsWith("Resource.class")); Resource relative1 = resource.createRelative("ClassPathResource.class"); assertEquals("ClassPathResource.class", relative1.getFilename()); assertTrue(relative1.getURL().getFile().endsWith("ClassPathResource.class")); assertTrue(relative1.exists()); Resource relative2 = resource.createRelative("support/ResourcePatternResolver.class"); assertEquals("ResourcePatternResolver.class", relative2.getFilename()); assertTrue(relative2.getURL().getFile().endsWith("ResourcePatternResolver.class")); assertTrue(relative2.exists()); } }
@Test public void resourceInjection() throws IOException { System.setProperty("logfile", "do_not_delete_me.txt"); try (AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ResourceInjectionBean.class)) { ResourceInjectionBean resourceInjectionBean = ac.getBean(ResourceInjectionBean.class); Resource resource = new ClassPathResource("do_not_delete_me.txt"); assertEquals(resource, resourceInjectionBean.resource); assertEquals(resource.getURL(), resourceInjectionBean.url); assertEquals(resource.getURI(), resourceInjectionBean.uri); assertEquals(resource.getFile(), resourceInjectionBean.file); assertArrayEquals(FileCopyUtils.copyToByteArray(resource.getInputStream()), FileCopyUtils.copyToByteArray(resourceInjectionBean.inputStream)); assertEquals(FileCopyUtils.copyToString(new EncodedResource(resource).getReader()), FileCopyUtils.copyToString(resourceInjectionBean.reader)); } finally { System.getProperties().remove("logfile"); } }