Java CRC32 Byte Array crc32(byte[] bytes)

Here you can find the source of crc32(byte[] bytes)

Description

crc

License

Open Source License

Declaration

public static String crc32(byte[] bytes) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .  j ava 2 s .  c om*/
 * AlbatrossUtils.java
 * 
 * Copyright (C) 2008 Mark Fenton
 * 
 * 
 * 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 <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String crc32(byte[] bytes) {
        java.util.zip.CRC32 x = new java.util.zip.CRC32();
        x.update(bytes);

        //java CRC is reversed (byte order) for what TS needs. SO....
        String crcString = Long.toHexString(x.getValue());

        //pad with leading 0s
        if (crcString.length() % 2 != 0) {
            crcString = "0" + crcString;
        }

        //reverse in pairs so bytes are in opposite order
        String reverseCrcString = crcString.substring(6, 8)
                + crcString.substring(4, 6) + crcString.substring(2, 4)
                + crcString.substring(0, 2);

        return reverseCrcString;
    }
}

Related

  1. computeCRC32(byte[] bytes)
  2. crc32(byte[] array)
  3. crc32(byte[] bts)
  4. CRC32(byte[] buffer)
  5. crc32(byte[] bytes)
  6. crc32(final byte[] bytes)
  7. crc32(String value)
  8. crc32Number(String s)
  9. crcBytes(byte[]... data)