Spread the love

Abstract Interface Checksum in Java

Spread the love

Abstract Interface Checksum in Java

Checksum interface defines the methods required to compute a checksum on a stream of data. The checksum is computed based on the bytes of data supplied by the update() methods, and the current value of the checksum can be obtained at any time with the getValue() method. reset() resets the checksum to its default value–use this method before beginning a new stream of data.

The Checksum interface defines the methods that are needed to compute a checksum value for a stream of data. The checksum value can be used for error checking purposes. Note, however, that the checksum value must fit into a long value, so this interface is not suitable for cryptographic checksum algorithms.

The Adler32 and CRC32 classes implement the Checksum interface, using the Adler-32 and CRC-32 algorithms, respectively. The CheckedInputStream and CheckedOutputStream classes provide a higher-level mechanism for computing checksums on data streams.

Note that the checksum value computed by a Checksum object and returned through the getValue() method must fit into a long value. Therefore, this interface is not suitable for the cryptographic checksum algorithms used in cryptography and security. The classes CheckedInputStream and CheckedOutputStream provide a higher-level API for computing a checksum on a stream of data.

The interface structure for Checksum is given as

public abstract interface java.util.zip.Checksum{
// Public Instance Methods
public abstract long getValue();
public abstract void reset();
public abstract void update(int b);
public abstract void update(byte[] b, int off, int len);
}

The details of the class structure are given as follows:

public abstract long getValue();

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

READ  Class Integer in Java
READ  Learn DataTypes in Java Quick and Easy Way

This method returns the current checksum value.

public abstract void reset();

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

public abstract void update(int b);

public abstract 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 abstract void update(byte[] b, int off, int len);

public abstract 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.




Spread the love
READ  Different Streams in Java
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis of instructions,...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Learn Quickly About DevOps Tools in a Fast and Efficient Manner

Introduction to DevOps tools DevOps tools are a collection of...

How to Collaborate between Development and Operations Team Fast and Effectively

Collaborate between Development and Operations Teams are the key...

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis...

EDITOR PICKS


Spread the love