Sunday, September 28, 2014

How to Calculate the Checks of a String Using Adler32 in Java

Instructions

    1

    Import the "Adler32" and "CheckedInputStream" modules, which calculate and store the checksum of a file or string. Use the following code:

    import java.util.zip.CheckedInputStream;
    import java.util.zip.Adler32;

    2

    Define a string value and convert it into a byte stream. Adler32 will only calculate checksums on incoming data streams:

    String s = "This is the String";
    byte buff[] = s.getBytes()'
    ByteArrayInputStream ba = new ByteArrayInputStream(buff);

    3

    Calculate the checksum using an Adler32 object:

    CheckedInputStream checked = new CheckedInputStream(ba, new Adler32());



No comments:

Post a Comment