装饰者模式
来源:互联网 发布:php 去掉斜线 编辑:程序博客网 时间:2024/05/22 07:40
package test.java.io;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* 装饰者模式
* 用LowerInputStream包装流,将经过该流的字母全部转换成小写的
*/
public class LowerInputStream extends FilterInputStream {
public LowerInputStream(InputStream in) {
super(in);
}
@Override
public int read() throws IOException {
int c = super.read();
return c == -1 ? c: Character.toLowerCase(c);
}
@Override
public int read(byte[] b, int offset, int len) throws IOException {
int result = super.read(b, offset, len);
for(int i=offset; i<offset+len; i++) {
b[i] = (byte) Character.toLowerCase(b[i]);
}
return result;
}
public static void main(String[] args) {
InputStream in = null;
int c = 0;
try {
in = new LowerInputStream(new BufferedInputStream(new FileInputStream("test.txt")));
while((c = in.read()) >= 0) {
System.out.print((char)c);
}
in.close();
} catch (Exception e) {
}
}
}
- 装饰者模式(Derector)
- 装饰者模式
- Decorator 装饰者模式
- 装饰者设计模式
- 装饰者模式
- 装饰者模式
- 装饰者模式
- 装饰者模式(Decorator)
- 装饰者模式
- 装饰者模式
- 装饰者模式
- 装饰者模式 DecoratorPattern
- 设计模式 - 装饰者
- 装饰者模式
- 装饰者模式
- 装饰者模式 - 2
- 装饰者模式
- 装饰者模式
- 打造高效排名
- 局部变量、全局变量、静态变量
- Jack's Tag——今天参加软件园开源讲座,Git、svn、apache各种听不懂
- 判断两个矩形是否相交
- TCP/IP学习(四)TCP缓冲区大小及限制
- 装饰者模式
- 从头到尾理解KMP算法
- ubuntu12.04安装jdk-7u5-linux-x64.tar.gz
- java RMI
- sharerd_ptr 实践,线程安全性,预定义宏以及FAQ [boost 1 49 0] .
- Android 开源项目推荐,学习不可错过 .
- XMLHttpRequest.setRequestHeader
- 黑马程序员-----交通灯管理系统
- hdu 1240 Asteroids!