Example usage for java.util.zip Adler32 update

List of usage examples for java.util.zip Adler32 update

Introduction

In this page you can find the example usage for java.util.zip Adler32 update.

Prototype

@Override
public void update(ByteBuffer buffer) 

Source Link

Document

Updates the checksum with the bytes from the specified buffer.

Usage

From source file:edu.cornell.med.icb.util.SimpleChecksum.java

/**
 * Takes a string and returns a that same string
 * with two additional characters which are a simple
 * checksum, each char will be "A".."Z". An empty
 * (no characters) or null string will just be
 * returned with no change.// ww  w  .ja  va2 s  . com
 * @param valToChecksum the string to add the checksum to
 * @return the string with the checksum
 */
public static String simpleChecksum(final String valToChecksum) {
    if (StringUtils.isEmpty(valToChecksum)) {
        return valToChecksum;
    }

    final Adler32 adler = new Adler32();
    adler.update(valToChecksum.getBytes());
    final long[] result = splitLong(adler.getValue());

    return String.format("%s%c%c", valToChecksum, CHECKSUM_CHARS[(int) result[0]],
            CHECKSUM_CHARS[(int) result[1]]);
}

From source file:com.google.gwt.resources.rg.GssResourceGenerator.java

private String computeDefaultPrefix(ResourceContext context) {
    SortedSet<JClassType> gssResources = computeOperableTypes(context);

    Adler32 checksum = new Adler32();

    for (JClassType type : gssResources) {
        checksum.update(Util.getBytes(type.getQualifiedSourceName()));
    }/*from   w  w w.  j  av  a2 s  . c  om*/

    int seed = Math.abs((int) checksum.getValue());

    return encode(seed) + "-";
}

From source file:org.pentaho.di.trans.steps.checksum.CheckSum.java

private Long calculCheckSum(Object[] r) throws Exception {
    Long retval;//  w  w  w.ja v a 2s  . com
    StringBuffer Buff = new StringBuffer();

    // Loop through fields
    for (int i = 0; i < data.fieldnr; i++) {
        String fieldvalue = getInputRowMeta().getString(r, data.fieldnrs[i]);
        Buff.append(fieldvalue);
    }

    if (meta.getCheckSumType().equals(CheckSumMeta.TYPE_CRC32)) {
        CRC32 crc32 = new CRC32();
        crc32.update(Buff.toString().getBytes());
        retval = new Long(crc32.getValue());
    } else {
        Adler32 adler32 = new Adler32();
        adler32.update(Buff.toString().getBytes());
        retval = new Long(adler32.getValue());
    }

    return retval;
}