fork download
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.util.zip.CRC32;
  6. import java.util.zip.CheckedInputStream;
  7. import java.util.zip.Checksum;
  8.  
  9.  
  10.  
  11. public class ChecksumChecker {
  12.  
  13. public static long getFileChecksum(String path) throws IOException {
  14. return getFileChecksum(new File(path));
  15. }
  16.  
  17. public static long getFileChecksum(File file) throws IOException {
  18. return getFileChecksum(new FileInputStream(file));
  19. }
  20.  
  21. public static long getFileChecksum(InputStream is) throws IOException {
  22. // Compute CRC-32 checksum
  23. byte[] tempBuf = new byte[1024];
  24. while (cis.read(tempBuf) >= 0) {
  25. }
  26. long csValue = cis.getChecksum().getValue();
  27.  
  28. return csValue;
  29. }
  30.  
  31. public static long getByteArrayChecksum(byte[] byteArray) {
  32. // Compute CRC-32 checksum
  33. Checksum checksum = new CRC32();
  34. checksum.update(byteArray, 0, byteArray.length);
  35. long csValue = checksum.getValue();
  36. checksum.reset();
  37.  
  38. return csValue;
  39. }
  40. }
  41.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:11: error: class ChecksumChecker is public, should be declared in a file named ChecksumChecker.java
public class ChecksumChecker {
       ^
1 error
stdout
Standard output is empty