Java 日看一类(64)之net包中的CacheRequest类和CacheResponse类

本文介绍了用于管理和操作HTTP响应缓存的两个核心类:CacheRequest和CacheResponse。CacheRequest类负责存储资源到缓存中,并提供了中断缓存操作的方法;CacheResponse类则用于从缓存中检索资源,提供输入流及响应头信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CacheRequest类无继承类

引入了如下包

import java.io.OutputStream;
import java.io.IOException;



该类的类头注释如下:

/**
 * Represents channels for storing resources in the
 * ResponseCache. Instances of such a class provide an
 * OutputStream object which is called by protocol handlers to
 * store the resource data into the cache, and also an abort() method
 * which allows a cache store operation to be interrupted and
 * abandoned. If an IOException is encountered while reading the
 * response or writing to the cache, the current cache store operation
 * will be aborted.
 *
 * @author Yingxian Wang
 * @since 1.5
 */

大意如下:

相当于在ResponseCache中存储资源的途径

该类的实例会提供一个输出流对象来存储资源到缓存中

并且提供abort方法允许缓存存储操作被打断和抛弃

如果在读取回复或者写入缓存时遇到了IO异常,当前的缓存存储操作将会中止



该类含有如下的成员方法:

获得可向缓存中写入的输出流

public abstract OutputStream getBody() throws IOException;

中止当前的缓存响应

public abstract void abort();



CacheResponse类无继承类

引入了如下包:

import java.io.InputStream;
import java.util.Map;
import java.util.List;
import java.io.IOException;


该类的类头注释如下:

/**
 * Represent channels for retrieving resources from the
 * ResponseCache. Instances of such a class provide an
 * InputStream that returns the entity body, and also a
 * getHeaders() method which returns the associated response headers.
 *
 * @author Yingxian Wang
 * @since 1.5
 */

大意如下:

相当于从ResponseCache中取回资源的途径

该类的实例会提供一个输入流并且完整返回该输入流

并且也会提供getHeaders方法

该方法会返回相关的响应头


该类含有如下的成员方法:

以map方式返回响应头

public abstract Map<String, List<String>> getHeaders() throws IOException;

返回从缓存输入的输入流

public abstract InputStream getBody() throws IOException;




这两个类都是针对缓存操作的,本身说明中和应用和网络操作关系不大(当然可以用在网络上,只是在任何方面都可以用得上,感觉封到IO里可能好些),不是很懂为什么要封在net包。该类主要是对高速缓存的资源管理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值