由于阿里有一些老项目都是由webx开发,所以就对该框架熟悉记录一下
1.spring的org.springframework.core.io.Resource
webx的Resource可以对标spring的org.springframework.core.io.Resource,但由于webx的资源框架自成体系,所以也有类似的结构,其意义是相似的
![](https://img.haomeiwen.com/i1297060/1a1eb51ac6fa1751.png)
2.webx的
2.1 Resource接口
/**
* 代表一个资源。
*/
public interface Resource {
URL getURL();
File getFile();
InputStream getInputStream() throws IOException;
boolean exists();
long lastModified();
int hashCode();
boolean equals(Object other);
}
2.2 Resource构造
![](https://img.haomeiwen.com/i1297060/b60d32724c5d11f9.png)
3. 构造Resource
3.1 构造函数参数
类 | 构造参数 |
---|---|
URLResource | URL |
FileResource | File |
ByteArrayResource | byte[] |
InputStreamResource | InputStream |
测试代码
@Test
public void existFile() throws Exception {
Resource urlResource = new URLResource(existsFile.toURI().toURL());
Resource fileResource = new FileResource(existsFile);
Resourcere byteArrayResource = new ByteArrayResource("hello".getBytes());
InputStream stream = existsFile.toURI().toURL().openStream();
Resource inputStreamResource = new InputStreamResource(stream);
}
4.ResourceLoader
资源装载器,同样可以对标spring的org.springframework.core.io.ResourceLoader
类 | 说明 |
---|---|
FileResourceLoader | 用来装载文件系统中的资源 |
ClasspathResourceLoader | 从classloader中装载资源 |
WebappResourceLoader | 从当前WEB应用中装载资源,也就是从ServletContext对象中装载资源 |
SuperResourceLoader | 从classloader中装载资源 |
5.ResourceAdapter
ResourceAdapter是将webx的Resource接口转换成spring的Resource接口
网友评论