Java ByteBuffer Get getCrcChecksum(ByteBuffer buffer)

Here you can find the source of getCrcChecksum(ByteBuffer buffer)

Description

Calculates the CRC32 checksum of the specified buffer.

License

Open Source License

Parameter

Parameter Description
buffer The buffer.

Return

The CRC32 checksum.

Declaration

public static int getCrcChecksum(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

import java.util.zip.CRC32;
import java.util.zip.Checksum;

public class Main {
    /**/*w ww  . ja  va2s . com*/
     * Calculates the CRC32 checksum of the specified buffer.
     * @param buffer The buffer.
     * @return The CRC32 checksum.
     */
    public static int getCrcChecksum(ByteBuffer buffer) {
        Checksum crc = new CRC32();
        for (int i = 0; i < buffer.limit(); i++) {
            crc.update(buffer.get(i));
        }
        return (int) crc.getValue();
    }
}

Related

  1. getByte(ByteBuffer byteBuffer)
  2. getByteAsShort(java.nio.ByteBuffer buffer)
  3. getByteLen(ByteBuffer buffer)
  4. getChars(ByteBuffer buf, int off, int count)
  5. getCPCharacter(ByteBuffer buffer)
  6. getCRLFCRLFIndex(ByteBuffer buffer)
  7. getCRLFIndex(ByteBuffer buffer)
  8. getCRLFLine(ByteBuffer buf)
  9. getData(ByteBuffer buf, int index, int size)