import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* 继承FilterInputStream,实现InputStream的装饰类
*
* Base Interface:InputStream
* be decorated: FileInputStream, StringBufferInputStream, ByteArrayInputStream
* decorator interface: FilterInputStream
* decorator: PushbackInputStream, BufferedInputStream, DataInputStream, LineNumberInputStream;
*
* @author neu_fufengrui@163.com
*
*/
public class LowerCaseInputStream extends FilterInputStream{
protected LowerCaseInputStream(InputStream in) {
super(in);
}
@Override
public int read() throws IOException {
int c = super.read();
return (c == -1 ? c : Character.toLowerCase((char)c));
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
int result = super.read(b, off, len);
for(int i = off; i < off+result; i++){
b[i] = (byte)Character.toLowerCase((char)b[i]);
}
return result;
}
//测试程序
public static void main(String[] args) throws IOException{
int c;
InputStream in = System.in;
in = new LowerCaseInputStream(in);
//循环读取输入内容,读到回车符(13)结束!
while((c = in.read()) >= 0 && c != 13){
System.out.print((char)c);
}
System.out.println();
System.out.println("end");
in.close();
}
}/*Output
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
*/