Java Checksum Calculate getChecksumAlder32(File file)

Here you can find the source of getChecksumAlder32(File file)

Description

get Checksum Alder

License

Open Source License

Declaration

public static long getChecksumAlder32(File file) throws IOException 

Method Source Code


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

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

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

import java.util.zip.Adler32;
import java.util.zip.CheckedInputStream;

public class Main {
    public static long getChecksumAlder32(File file) throws IOException {
        BufferedInputStream bufferedInputStream = null;
        try {//from  w ww.  j av a  2 s  . c  o m
            bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
            return getChecksumAlder32(bufferedInputStream);
        } catch (IOException e) {
            throw e;
        } finally {
            if (bufferedInputStream != null) {
                bufferedInputStream.close();
            }
        }
    }

    public static long getChecksumAlder32(InputStream inputStream) throws IOException {
        if (inputStream == null) {
            return 0;
        }
        CheckedInputStream cis = null;
        try {
            // Compute Adler-32 checksum
            cis = new CheckedInputStream(inputStream, new Adler32());
            byte[] tempBuf = new byte[128];
            while (cis.read(tempBuf) >= 0) {
                // do nothing
            }
            return cis.getChecksum().getValue();
        } catch (IOException e) {
            throw e;
        } finally {
            if (cis != null) {
                cis.close();
            }
        }
    }
}

Related

  1. generateChecksum(String pType, String pInFile)
  2. generateCheckSum(String string)
  3. getChecksum(byte[] buffer, int offset, int length)
  4. getChecksum(final File file)
  5. getCheckSum(String filePath)
  6. getCheckSums(String archiveFile)