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设计模式,本想留个笔记,看了此文,觉得经典,原样转来
本文介绍了FilterInputStream类,它是一个可包裹任何输入流类的Decorator,本质是抽象类,不做处理但提供方法复制层,通常将方法调用转发给封闭的父流类。还列举了从其派生的有趣类,如BufferedInputStream、CheckedInputStream等。
1105

被折叠的 条评论
为什么被折叠?



