FileDocCategorySizeDatePackage
CheckSum.javaAPI DocExample1139Sat Nov 25 12:56:14 GMT 2000None

CheckSum

public class CheckSum extends Object
CheckSum - remove leading spaces
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: CheckSum.java,v 1.2 2000/11/25 17:56:14 ian Exp $

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] av)

        CheckSum c = new CheckSum();
		int sum = 0;
        if (av.length == 0)
            sum = c.process(new BufferedReader(
					new InputStreamReader(System.in)));
        else for (int i=0; i<av.length; i++)
			try {
				sum += c.process(new BufferedReader(new FileReader(av[i])));
			} catch (FileNotFoundException e) {
				System.err.println(e);
			}
		System.out.println(sum);
    
public intprocess(java.io.BufferedReader is)
CheckSum one file, given an open BufferedReader.

		//+
		int sum = 0;
        try {
            String inputLine;

            while ((inputLine = is.readLine()) != null) {
				int i;
				for (i=0; i<inputLine.length(); i++) {
					sum += inputLine.charAt(i);
				}
            }
            is.close();
        } catch (IOException e) {
            System.out.println("IOException: " + e);
		} finally {
			return sum;
        }
		//-