
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();
}
}
}
この
I/O
デコレータをテストする簡単なコードを書きましょう。
% java InputTest
i know the decorator pattern therefore I rule!
%
ファイル 編集 ウィンドウ ヘルプ デコレータが支配
試してみましょう。
FileInputStream
を設定し、まず
BufferedInputStream
で装飾してから新し
い
LowerCaseInputStream
フィルタで装飾
します。
ストリームを使ってファイルの末
尾まで文字を読み取り、そのまま
出力するだけです。
I know the Decorator Pattern therefore I RULE!
test.txt
ファイル
新しい
Java I/O