decorator 模式 - 编程吧

上一篇 | 下一篇

decorator 模式

发布: 2006-9-14 21:11 | 作者: 佚名 | 来源: 不详 | 查看: 69次





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.

TAG: 编程

字号: | 推荐给好友

 

评分:0

我来说两句

seccode