Java CRC Calculate computeCRC(InputStream in)

Here you can find the source of computeCRC(InputStream in)

Description

compute CRC

License

Open Source License

Declaration

public static long computeCRC(InputStream in) 

Method Source Code


//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.Adler32;
import java.util.zip.CheckedInputStream;

public class Main {
    public static long computeCRC(InputStream in) {
        long unitCRC = 0;

        BufferedInputStream bufferedInputStream = null;

        try {//from  w ww .  ja  va2  s  .  c  o m
            bufferedInputStream = new BufferedInputStream(in);

            // Compute Adler-32 checksum
            CheckedInputStream cis = new CheckedInputStream(bufferedInputStream, new Adler32());
            byte[] tempBuf = new byte[128];
            while (cis.read(tempBuf) >= 0) {
                // do nothing
            }
            unitCRC = cis.getChecksum().getValue();
        } catch (IOException e) {
            return -1;
        } finally {
            try {
                bufferedInputStream.close();
            } catch (Exception e) {
                // ignore me even if i'm null
            }
        }
        return unitCRC;
    }
}

Related

  1. calculateCRC(byte[] data, int offset, int len)
  2. calculateCRC(String digitsToCheck)
  3. calculateCRC(String id)
  4. calculateCrc16(byte[] buffer)
  5. calculateCRC32(byte[] buf, int off, int len)
  6. computeCRC32(File file)
  7. computeCrc32(InputStream is)
  8. CRC(String message)
  9. crc16(byte[] bytes)