当前位置: 首页 > wzjs >正文

抚州网站制作企业软文

抚州网站制作,企业软文,腾讯云怎样做网站,app开发公司历程概述Resource Resource 接口为处理和访问不同类型资源(如文件、URL、输入流等)提供了统一的 API,支持资源的存在性检查、读取、转换等操作。 public interface Resource extends InputStreamSource {boolean exists();default boolean isReadable…

Resource

Resource 接口为处理和访问不同类型资源(如文件、URL、输入流等)提供了统一的 API,支持资源的存在性检查、读取、转换等操作。

public interface Resource extends InputStreamSource {boolean exists();default boolean isReadable() {return exists();}default boolean isOpen() {return false;}default boolean isFile() {return false;}URL getURL() throws IOException;URI getURI() throws IOException;File getFile() throws IOException;default ReadableByteChannel readableChannel() throws IOException {return Channels.newChannel(getInputStream());}default byte[] getContentAsByteArray() throws IOException {return FileCopyUtils.copyToByteArray(getInputStream());}default String getContentAsString(Charset charset) throws IOException {return FileCopyUtils.copyToString(new InputStreamReader(getInputStream(), charset));}long contentLength() throws IOException;long lastModified() throws IOException;Resource createRelative(String relativePath) throws IOException;@NullableString getFilename();String getDescription();}
public interface InputStreamSource {InputStream getInputStream() throws IOException;
}
实现类描述
UrlResource用于封装 java.net.URL,可以访问任何通过 URL 访问的资源,如文件、HTTPS、FTP 等。
ClassPathResource用于从类路径加载资源,支持使用类加载器或特定类来加载资源。
FileSystemResource基于 java.io.File 的实现,支持文件系统路径,采用 Java NIO API 进行操作。
PathResource基于 java.nio.file.Path 的实现,采用 NIO API,支持文件和 URL 解析,且实现了 WritableResource 接口。
ServletContextResource用于 ServletContext 资源,解析相对路径并在 Web 应用的根目录下查找资源。
InputStreamResource封装已打开的 InputStream,适用于流式访问已打开的资源,避免多次读取。
ByteArrayResource基于给定字节数组的实现,通过 ByteArrayInputStream 来加载内容,适合加载内存中的数据。

ResourceLoader

ResourceLoader 接口用于资源加载策略,通常在 Spring 应用中用于加载文件、类路径或其他类型的资源。它的子接口和实现类则为其功能扩展,支持不同类型的应用上下文或资源解析需求。|

public interface ResourceLoader {/** Pseudo URL prefix for loading from the class path: "classpath:". */String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX;Resource getResource(String location);@NullableClassLoader getClassLoader();}

DefaultResourceLoader

DefaultResourceLoader 是 Spring 中用于加载各种类型资源的默认实现,支持通过类路径、文件系统、URL 等方式加载,并允许扩展协议解析器。

// Direct Known Subclasses:
// AbstractApplicationContext, ClassRelativeResourceLoader, FileSystemResourceLoader, ServletContextResourceLoader
public class DefaultResourceLoader implements ResourceLoader {@Nullableprivate ClassLoader classLoader;private final Set<ProtocolResolver> protocolResolvers = new LinkedHashSet<>(4);private final Map<Class<?>, Map<Resource, ?>> resourceCaches = new ConcurrentHashMap<>(4);public DefaultResourceLoader() {}public DefaultResourceLoader(@Nullable ClassLoader classLoader) {this.classLoader = classLoader;}public void addProtocolResolver(ProtocolResolver resolver) {Assert.notNull(resolver, "ProtocolResolver must not be null");this.protocolResolvers.add(resolver);}@SuppressWarnings("unchecked")public <T> Map<Resource, T> getResourceCache(Class<T> valueType) {return (Map<Resource, T>) this.resourceCaches.computeIfAbsent(valueType, key -> new ConcurrentHashMap<>());}public void clearResourceCaches() {this.resourceCaches.clear();}@Overridepublic Resource getResource(String location) {Assert.notNull(location, "Location must not be null");for (ProtocolResolver protocolResolver : getProtocolResolvers()) {Resource resource = protocolResolver.resolve(location, this);if (resource != null) {return resource;}}if (location.startsWith("/")) {return getResourceByPath(location);}else if (location.startsWith(CLASSPATH_URL_PREFIX)) {return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());}else {try {// Try to parse the location as a URL...URL url = ResourceUtils.toURL(location);return (ResourceUtils.isFileURL(url) ? new FileUrlResource(url) : new UrlResource(url));}catch (MalformedURLException ex) {// No URL -> resolve as resource path.return getResourceByPath(location);}}}protected Resource getResourceByPath(String path) {return new ClassPathContextResource(path, getClassLoader());}protected static class ClassPathContextResource extends ClassPathResource implements ContextResource {public ClassPathContextResource(String path, @Nullable ClassLoader classLoader) {super(path, classLoader);}@Overridepublic String getPathWithinContext() {return getPath();}@Overridepublic Resource createRelative(String relativePath) {String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);return new ClassPathContextResource(pathToUse, getClassLoader());}}
}

ResourcePatternResolver

ResourcePatternResolverResourceLoader 的扩展接口,提供了通过模式(如 Ant 风格路径)解析位置并返回 Resource 对象的功能。它支持 classpath*: 前缀来获取类路径和模块路径中所有匹配的资源。

// "classpath:META-INF/config.xml" 只匹配 第一个 META-INF/config.xml
// "classpath*:META-INF/config.xml" 匹配 所有 JAR 包 和 所有 META-INF 目录 下的 config.xml// PathMatchingResourcePatternResolver
public interface ResourcePatternResolver extends ResourceLoader {String CLASSPATH_ALL_URL_PREFIX = "classpath*:";Resource[] getResources(String locationPattern) throws IOException;}

ResourceLoaderAware

ResourceLoaderAware 接口允许对象在 Spring 容器中获取并使用 ResourceLoader 来加载资源。

public interface ResourceLoaderAware {void setResourceLoader(ResourceLoader resourceLoader);
}

·

http://www.dtcms.com/wzjs/317224.html

相关文章:

  • 临沂集团网站建设抖音怎么运营和引流
  • 湖南网站建设开发百度站内搜索的方法
  • 建网站靠什么赚钱品牌策划公司
  • 晋城市网站建设网站排名监控工具
  • 网站建设思路方案网络营销怎么推广
  • 新乡市做网站直销系统网站百度seo查询系统
  • 个人免费网站建设模板郑州网站优化外包
  • wordpress 12张表seo标签优化
  • 2023一般纳税人企业所得税怎么算兰州网站seo优化
  • 网站空间管理平台关键词优化和seo
  • 专业网站建设技术北京搜索引擎推广服务
  • 网站点击量设计软件开发自学步骤
  • wordpress 获取置顶文章佛山seo技术
  • 鞍山做网站哪家好seo技术培训学校
  • 建设网站简单的需要多少天杭州seo俱乐部
  • 竞价广告是怎么推广的长沙竞价优化
  • 网站建设的课程搜索到的相关信息
  • 顺德企业网站制作天津网站快速排名提升
  • 企业定制网站价格表如何推广宣传一个品牌
  • 苏州cms模板建站宝深圳seo推广
  • 网站代码查看网络推广外包一年多少钱
  • 专门做母婴的网站有哪些如何做网站的教程
  • 一站式营销推广东莞快速排名
  • 高端网站定制提高工作效率的工具
  • 深圳网络营销网站建设营销策划的概念
  • 建设网站的目的和意义是什么百度广告投放代理商
  • 重庆沛宣网站建设近期重大新闻事件10条
  • 网站开发 资质海南网站网络推广
  • 博彩网站开发建设指数搜索
  • 建企业网站的步骤杭州百度推广