Here you can find the source of crc32(String data)
Parameter | Description |
---|---|
data | a parameter |
Parameter | Description |
---|---|
RuntimeException | if UTF-8 is not a supported character set |
public static long crc32(String data)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.util.zip.CRC32; import java.util.zip.Checksum; public class Main { /**/*from www. ja v a 2 s .com*/ * Generates a CRC 32 Value of String passed * * @param data * @return long crc32 value of input. -1 if string is null * @throws RuntimeException if UTF-8 is not a supported character set */ public static long crc32(String data) { if (data == null) { return -1; } try { // get bytes from string byte bytes[] = data.getBytes("UTF-8"); Checksum checksum = new CRC32(); // update the current checksum with the specified array of bytes checksum.update(bytes, 0, bytes.length); // get the current checksum value return checksum.getValue(); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } }