001package headfirst.decorator.io; 002 003import java.io.FilterInputStream; 004import java.io.IOException; 005import java.io.InputStream; 006 007public class LowerCaseInputStream extends FilterInputStream { 008 009 public LowerCaseInputStream(InputStream in) { 010 super(in); 011 } 012 013 public int read() throws IOException { 014 int c = super.read(); 015 return (c == -1 ? c : Character.toLowerCase((char)c)); 016 } 017 018 public int read(byte[] b, int offset, int len) throws IOException { 019 int result = super.read(b, offset, len); 020 for (int i = offset; i < offset+result; i++) { 021 b[i] = (byte)Character.toLowerCase((char)b[i]); 022 } 023 return result; 024 } 025}