Class CRC32 in Java

digitization, transformation, binary

Class CRC32 in Java

CRC32 class implements the Checksum interface and computes a checksum on a stream of data using the CRC-32 algorithm. The CheckedInputStream and CheckedOutputStream classes provide a higher-level interface to computing checksums on streams of data.

This algorithm is significantly slower than Adler-32 and only slightly more reliable.

Ads code goes here

The class structure of Class CRC32 in Java is given as

public class java.util.zip.CRC32 extends java.lang.Object implements java.util.zip.Checksum {
// Default Constructor: 
public CRC32();
// Public Instance Methods
public long getValue(); // From Checksum
public void reset(); // From Checksum
public void update(int b); // From Checksum
public native void update(byte[] b, int off, int len); // From Checksum
public void update(byte[] b);
}

The details of the class structure are given as follows:

public CRC32();

public CRC32() constructor creates a CRC32 object.

public long getValue();

public long getValue() method returns the current value of this checksum.

This method returns the current checksum value.

public void reset();

public void reset() method resets the checksum to its initial value, making it appear as though it has not been updated by any data.

public void update(int b);

public void update(int b) method adds the specified value to the data stream and updates the checksum value. The
method uses only the lowest eight bits of the given int.

Parameter
b – The value to be added to the data stream for the checksum calculation.

public void update(byte[] b);

public void update(byte[] b) method adds the bytes from the specified array to the data stream and updates the checksum value.

READ  Abstract Interface Observer in Java

Parameter
b – An array of bytes to be added to the data stream for the checksum calculation.

public native void update(byte[] b, int off, int len);

public native void update(byte[] b, int off, int len) method adds len bytes from the specified array, starting at off, to the data stream and updates the checksum value.

Parameter
b – An array of bytes to be added to the data stream for the checksum calculation.
off – An offset into the byte array.
len – The number of bytes to use.

Apart from these CRC32 class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)

Share and Enjoy !

Leave a Comment

Your email address will not be published. Required fields are marked *