Java CRC Calculate computeCRC32(File file)

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

Description

compute CRC

License

Open Source License

Declaration

private static long computeCRC32(File file) throws IOException 

Method Source Code

//package com.java2s;
/*//from  w w  w.j av a 2s  . c o m
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.zip.CRC32;

public class Main {
    private static long computeCRC32(File file) throws IOException {
        byte buf[] = new byte[32 * 1024];
        CRC32 crc = new CRC32();
        crc.reset();
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
            int bytesRead;
            while ((bytesRead = fis.read(buf)) != -1) {
                crc.update(buf, 0, bytesRead);
            }
            return crc.getValue();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                }
            }
        }
    }
}

Related

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