深入Spring IOC源码之Resource(三)

2014-11-24 10:36:17 · 作者: · 浏览: 3
athWithContext方法依然返回path字符串:

public boolean exists() {

try {

URL url = this.servletContext.getResource(this.path);

return (url != null);

}

catch (MalformedURLException ex) {

return false;

}

}

public InputStream getInputStream() throws IOException {

InputStream is = this.servletContext.getResourceAsStream(this.path);

if (is == null) {

throw new FileNotFoundException("Could not open " + getDescription());

}

return is;

}

public URL getURL() throws IOException {

URL url = this.servletContext.getResource(this.path);

if (url == null) {

throw new FileNotFoundException(

getDescription() + " cannot be resolved to URL because it does not exist");

}

return url;

}

public File getFile() throws IOException {

String realPath = WebUtils.getRealPath(this.servletContext, this.path);

return new File(realPath);

}

public Resource createRelative(String relativePath) {

String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);

return new ServletContextResource(this.servletContext, pathToUse);

}