美文网首页
webx笔记-Resource

webx笔记-Resource

作者: 兴浩 | 来源:发表于2018-10-06 18:59 被阅读11次

由于阿里有一些老项目都是由webx开发,所以就对该框架熟悉记录一下

1.spring的org.springframework.core.io.Resource

webx的Resource可以对标spring的org.springframework.core.io.Resource,但由于webx的资源框架自成体系,所以也有类似的结构,其意义是相似的

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构造

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接口

相关文章

网友评论

      本文标题:webx笔记-Resource

      本文链接:https://www.haomeiwen.com/subject/ruihaftx.html