Checksum: update(int b) : Checksum « java.util.zip « Java by API






Checksum: update(int b)

       

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.CRC32;
import java.util.zip.Checksum;

public class Main {

  public static void main(String[] args) throws IOException {
    FileInputStream fin = new FileInputStream(args[0]);
    System.out.println(args[0] + ":\t" + getCRC32(fin));
    fin.close();
  }

  public static long getCRC32(InputStream in) throws IOException {
    Checksum cs = new CRC32();

    for (int b = in.read(); b != -1; b = in.read()) {
      cs.update(b);
    }
    return cs.getValue();
  }
}

   
    
    
    
    
    
    
  








Related examples in the same category

1.implements Checksum
2.Checksum: getValue()
3.Checksum: reset()