|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectastex.CRC32
public class CRC32
Calculates the CRC32 - 32 bit Cyclical Redundancy Check
This check is used in numerous systems to verify the integrity
of information. It's also used as a hashing function. Unlike a regular
checksum, it's sensitive to the order of the characters.
It produces a 32 bit (Java int.
This Java programme was translated from a C version I had written.
This software is in the public domain.
When calculating the CRC32 over a number of strings or byte arrays the previously calculated CRC is passed to the next call. In this way the CRC is built up over a number of items, including a mix of strings and byte arrays.
CRC32 crc = new CRC32();
int crcCalc = crc.crc32("Hello World");
crcCalc = crc.crc32("How are you?", crcCalc);
crcCalc = crc.crc32("I'm feeling really good, how about you?", crcCalc);
The line int crcCalc = crc.crc32("Hello World"); is equivalent
to int crcCalc = crc.crc32("Hello World", -1);.
When starting a new CRC calculation the "previous crc" is set to
0xFFFFFFFF (or -1).
The table only needs to be built once. You may use it to generate
many CRC's.
Method Summary
static intcrc32(byte[] buffer)
Convenience method for generating a CRC from a byte array.
static intcrc32(byte[] buffer,
int crc)
Convenience method for generating a CRC from a series of byte arrays.
static intcrc32(byte[] buffer,
int start,
int count,
int lastcrc)
General CRC generation function.
static intcrc32(int[] buffer,
int start,
int count,
int lastcrc)
General CRC generation function.
static intcrc32(java.lang.String buffer)
Convenience mithod for generating a CRC from a single String.
static intcrc32(java.lang.String buffer,
int crc)
Convenience method for generating a CRC from a series of String's.
static voidmain(java.lang.String[] args)
Tests CRC32.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Method Detail
main
public static void main(java.lang.String[] args)
Eg: java CRC32 "Howdy, I'm A Cowboy"
args - the string used to calculate the CRC32
crc32
public static int crc32(java.lang.String buffer)
String.
buffer - string to generate the CRC32
crc32
public static int crc32(byte[] buffer)
byte array.
buffer - byte array to generate the CRC32
crc32
public static int crc32(java.lang.String buffer,
int crc)
String's.
buffer - string to generate the CRC32crc - previously generated CRC32.
crc32
public static int crc32(byte[] buffer,
int crc)
byte arrays.
buffer - byte array to generate the CRC32crc - previously generated CRC32.
crc32
public static int crc32(byte[] buffer,
int start,
int count,
int lastcrc)
buffer - byte array to generate the CRC32start - byte start positioncount - number of byte's to include in CRC calculationcrc - previously generated CRC32.
crc32
public static int crc32(int[] buffer,
int start,
int count,
int lastcrc)
buffer - byte array to generate the CRC32start - byte start positioncount - number of byte's to include in CRC calculationcrc - previously generated CRC32.
Overview
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD