List of usage examples for org.springframework.core.io Resource Resource
Resource
From source file:com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.java
@Override public Resource getResource(String location) { final Resource r = super.getResource(location); try {/* ww w . j a v a2s.c o m*/ files.add(r.getFile()); } catch (IOException e) { log.debug(e); } return new Resource() { Resource r2 = r; public boolean exists() { return r2.exists(); } public InputStream getInputStream() throws IOException { return r2.getInputStream(); } public boolean isReadable() { return r2.isReadable(); } public boolean isOpen() { return r2.isOpen(); } public URL getURL() throws IOException { return r2.getURL(); } public URI getURI() throws IOException { return r2.getURI(); } public File getFile() throws IOException { return r2.getFile(); } public long lastModified() throws IOException { return r2.lastModified(); } public Resource createRelative(String relativePath) throws IOException { Resource r = r2.createRelative(relativePath); files.add(r.getFile()); return r; } public String getFilename() { return r2.getFilename(); } public String getDescription() { return r2.getDescription(); } public long contentLength() throws IOException { return r2.contentLength(); } @Override public String toString() { return r2.toString(); } }; }
From source file:org.jahia.services.render.filter.StaticAssetsFilter.java
private static Resource getResourceFromFile(String workspace, final String fFilePath) { try {// w ww . ja va2 s . c om final JCRNodeWrapper contentNode = JCRSessionFactory.getInstance().getCurrentUserSession(workspace) .getNode(fFilePath); return new Resource() { @Override public boolean exists() { return true; } @Override public boolean isReadable() { return false; } @Override public boolean isOpen() { return false; } @Override public URL getURL() throws IOException { return null; } @Override public URI getURI() throws IOException { return null; } @Override public File getFile() throws IOException { return null; } @Override public long contentLength() throws IOException { return contentNode.getFileContent().getContentLength(); } @Override public long lastModified() throws IOException { return contentNode.getLastModifiedAsDate().getTime(); } @Override public Resource createRelative(String relativePath) throws IOException { return null; } @Override public String getFilename() { return contentNode.getName(); } @Override public String getDescription() { return null; } @Override public InputStream getInputStream() throws IOException { return contentNode.getFileContent().downloadFile(); } }; } catch (RepositoryException e) { // Cannot get resource } return null; }