
public class LowerCaseInputStream extends FilterInputStream {
public LowerCaseInputStream(InputStream in) {
super(in);
}
public int read() throws IOException {
int c = in.read();
return (c == -1 ? c : Character.toLowerCase((char)c));
}
public int read(byte[] b, int offset, int len) throws IOException {
int result = in.read(b, offset, len);
for (int i = offset; i < offset+result; i++) {
b[i] = (byte)Character.toLowerCase((char)b[i]);
}
return result;
}
}
独自の
Java I/O
デコレータを書く
これまでの説明で、あなたは
Decorator
パターンのことを理解
し、
I/O
クラス図も確認しました。これで独自の入力デコレータ
を書く準備ができたはずです。
さっそく入力ストリームで大文字を小文字に変換するデコ
レータを書いてみてはどうでしょうか。つまり、「
I know the
Decorator Pattern therefore I RULE! ...