Java CRC Calculate calculateCRC32(byte[] buf, int off, int len)

Here you can find the source of calculateCRC32(byte[] buf, int off, int len)

Description

Calculates the CRC32 of the given bytes.

License

Open Source License

Parameter

Parameter Description
buf the byte array to calculate CRC32 on
off the offset within buf at which the CRC32 calculation will start
len the number of bytes on which to calculate the CRC32

Return

the CRC32 value.

Declaration

static public int calculateCRC32(byte[] buf, int off, int len) 

Method Source Code

//package com.java2s;
/*//from w  w w  .  j  a  v a2s.c om
 *  (c) copyright 2003-2007 Amichai Rothman
 *
 *  This file is part of the Java TNEF package.
 *
 *  The Java TNEF package 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; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The Java TNEF package 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, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

public class Main {
    /** The lookup table used in the CRC32 calculation */
    static int[] CRC32_TABLE;

    /**
     * Calculates the CRC32 of the given bytes. The CRC32 calculation is similar
     * to the standard one as demonstrated in RFC 1952, but with the inversion
     * (before and after the calculation) ommited.
     * 
     * @param buf
     *            the byte array to calculate CRC32 on
     * @param off
     *            the offset within buf at which the CRC32 calculation will
     *            start
     * @param len
     *            the number of bytes on which to calculate the CRC32
     * @return the CRC32 value.
     */
    static public int calculateCRC32(byte[] buf, int off, int len) {
        int c = 0;
        int end = off + len;
        for (int i = off; i < end; i++) {
            c = CRC32_TABLE[(c ^ buf[i]) & 0xFF] ^ (c >>> 8);
        }
        return c;
    }
}

Related

  1. calculateCRC(byte[] buff, int count)
  2. calculateCRC(byte[] data, int offset, int len)
  3. calculateCRC(String digitsToCheck)
  4. calculateCRC(String id)
  5. calculateCrc16(byte[] buffer)
  6. computeCRC(InputStream in)
  7. computeCRC32(File file)
  8. computeCrc32(InputStream is)
  9. CRC(String message)