Java CRC32 Byte Array getCrc32asInt(byte[] in)

Here you can find the source of getCrc32asInt(byte[] in)

Description

Use this method to calculate the CRC32 signature of a byte array.

License

Open Source License

Parameter

Parameter Description
in input array of bytes

Return

The CRC32 signature of the array as an int or -1 if in == null or byte array is empty

Declaration

public static int getCrc32asInt(byte[] in) 

Method Source Code

//package com.java2s;
/**/*from  w w  w .j av a2  s .  co m*/
 * <PRE>
 * Name   : com.solidmatrix.regxmaker.util.shared.ConsoleUtils
 * Project: RegXmaker Library
 * Version: 1.1
 * Tier   : N/A (Function Class)
 * Author : Gennadiy Shafranovich
 * Purpose: General utilities for console based applications
 *
 * Copyright (C) 2001, 2004 SolidMatrix Technologies, Inc.
 * This file is part of RegXmaker Library.
 *
 * RegXmaker Library is is free software; you can redistribute it and/or modify
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * RegXmaker library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Comments: Full, with javadoc.
 *
 * Modification History
 *
 * 01-28-2001  GS Created
 * 07-02-2001  GS Added a more general readFull() method to read 
 *                entire contents of a stream. readFullFile now
 *                used this method to read from an underlying
 *                FileInputStream.
 *
 * 07-05-2004 YS Added licensing information
 * </PRE>
 */

import java.util.zip.CRC32;

public class Main {
    /**
     * Use this method to calculate the CRC32 signature of a byte array.
     *
     * @param   in  input array of bytes
     * @return  The CRC32 signature of the array as an int or -1 if in == null or byte array is empty
     */
    public static int getCrc32asInt(byte[] in) {
        if (in == null || in.length == 0)
            return -1;

        CRC32 crc = new CRC32();
        crc.update(in);
        return (int) crc.getValue();
    }
}

Related

  1. crcBytes(byte[]... data)
  2. createRandomCrc32Hex()
  3. getCRC()
  4. getCrc32(byte[] buf)
  5. getCRC32(String str)
  6. getCRC32Checksum(byte[] bytes)
  7. getCRC32Checksum(String pString)