Hi there fellows:
Hope everyone is doing great happily programming with passion.

I need your help as I'm stuck on this exercise for a while now. It says that I 
should add two classes, namely ChangeToUpperCaseInputStream and 
ChangeToUpperCaseOutputStream. I wrote them. Here is an example:

import java.io.FilterInputStream;
import java.io.InputStream;
import java.io.IOException;

public class ChangeToUpperCaseInputStream extends FilterInputStream  {
    
    public ChangeToUpperCaseInputStream(InputStream in) {
        super(in);
    }

    public int read() throws IOException {
        int b = in.read();
        if (b != -1) {
            b= Character.toUpperCase(b);
        }
        return b;
    }

    public int read(byte[] b) throws IOException {
        int len;
        len = in.read(b, 0, b.length);
        if (len != -1) {
            for (int i=0; i<len; i++)
                b[i]= (byte) Character.toUpperCase (b[i]);
        }
        return len;
    }

    public int read(byte[] b, int off, int len) throws IOException {
        len = in.read(b, off, len);
        if (len != -1) {
            for (int i=off; i<(off+len); i++)
                b[i]= (byte) Character.toUpperCase (b[i]);
        }
        return len; 
    }
}


And the main class

public class FilterInputOutputStream {
    
    public static void main(String[] args) throws IOException {

       Adler32 inChecker = new Adler32();
       Adler32 outChecker = new Adler32();
       CheckedInputStream in = null;
       CheckedOutputStream out = null;
       

       try {
           in = new CheckedInputStream(
               new FileInputStream("farrago.txt"),
               inChecker);
           out = new CheckedOutputStream(
                new FileOutputStream("outagain.txt"),
                outChecker);
       } catch (FileNotFoundException e) {
           System.err.println("CheckedIOTest: " + e);
           System.exit(-1);
       } catch (IOException e) {
           System.err.println("CheckedIOTest: " + e);
           System.exit(-1);
       }

       int c;

       while ((c = in.read()) != -1)
          out.write(c);

       System.out.println("Input stream check sum: " +
              inChecker.getValue());
       System.out.println("Output stream check sum: " +
              outChecker.getValue());

       in.close();
       out.close();
    }
}

My question is how can I implement the changetouppercase class in main sos as 
to produce the desired results?

Thanks for Any help you can provide.

Victor Bruno

                                          

-- 
To post to this group, send email to javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to 
javaprogrammingwithpassion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to