decorator 模式

本文介绍了FilterInputStream类,它是一个可包裹任何输入流类的Decorator,本质是抽象类,不做处理但提供方法复制层,通常将方法调用转发给封闭的父流类。还列举了从其派生的有趣类,如BufferedInputStream、CheckedInputStream等。

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

decorator for non-visualable class e.g. java.io.*

The class FilterInputStream itself simply overrides all methods of InputStream with versions that pass all requests to the underlying input stream. Subclasses of FilterInputStream may further override some of these methods as well as provide additional methods and fields. 

The FilterInputStream class is thus a Decorator that can be wrapped around any input stream class. It is essentially an abstract class that doesn’t do any processing, but provides a layer where the relevant methods have been duplicated. It normally forwards these method calls to the enclosed parent stream class. The interesting classes derived from FilterInputStream include: 

BufferedInputStream Adds buffering to stream so that every call does

not cause I/O to occur.

CheckedInputStream  Maintains a checksum of bytes as they are read

DataInputStream     Reads primitive types (Long, Boolean, Float, etc.)

from the input stream.

DigestInputStream   Computes a MessageDigest of any input stream.

InflaterInputStream Implements methods for uncompressing data.

PushbackInputStream Provides a buffer where data can be “unread,” if

during parsing you discover you need to back up.

看了看Decorator设计模式,本想留个笔记,看了此文,觉得经典,原样转来

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值