首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

Head First 设计方式学习笔记(三)装饰者模式续

2012-08-10 
Head First 设计模式学习笔记(三)装饰者模式续装饰者模式续。??????public class LowerCaseInputStream ext

Head First 设计模式学习笔记(三)装饰者模式续

装饰者模式续。

?

?

Head First 设计方式学习笔记(三)装饰者模式续

?

?

?

?

public class LowerCaseInputStream extends FilterInputStream {public LowerCaseInputStream(InputStream in) {super(in);}public int read() throws IOException {int c = super.read();return (c == -1 ? c : Character.toLowerCase((char)c));}public int read(byte[] b, int offset, int len) throws IOException {int result = super.read(b, offset, len);for (int i = offset; i < offset+result; i++) {b[i] = (byte)Character.toLowerCase((char)b[i]);}return result;}}
?
public class InputTest {public static void main(String[] args) throws IOException {int c;try {InputStream in =new LowerCaseInputStream(new BufferedInputStream(new FileInputStream("test.txt")));while((c = in.read()) >= 0) {System.out.print((char)c);}in.close();} catch (IOException e) {e.printStackTrace();}}}
?

?

?

热点排行