Example usage for java.util.zip Checksum update

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

Introduction

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

Prototype

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

Source Link

Document

Updates the current checksum with the specified array of bytes.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = "some data".getBytes();

    Checksum checksumEngine = new Adler32();
    checksumEngine.update(bytes, 0, bytes.length);
    long checksum = checksumEngine.getValue();
    System.out.println(checksum);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = "some data".getBytes();

    // Compute Adler-32 checksum
    Checksum checksumEngine = new CRC32();
    checksumEngine.update(bytes, 0, bytes.length);
    long checksum = checksumEngine.getValue();

    checksumEngine.reset();/*from   w  w  w. ja v a 2  s.  co m*/
}

From source file:Main.java

public static long doChecksum(String text) throws UnsupportedEncodingException {
    byte bytes[] = text.getBytes("UTF-8"); // This makes this hash function platform independent
    Checksum checksum = new CRC32();
    checksum.update(bytes, 0, bytes.length);
    long lngChecksum = checksum.getValue();
    return lngChecksum;
}

From source file:ChecksumCalculator.java

public static long compute(byte[] data, int start, int length) {
    Checksum checksum = new Adler32();
    checksum.update(data, start, length);
    return checksum.getValue();
}

From source file:net.sourceforge.jaulp.file.checksum.ChecksumUtils.java

/**
 * Gets the checksum from the given byte array with an instance of.
 *
 * @param bytes/* w w  w  .  ja va 2s . c o m*/
 *            The byte array.
 * @return The checksum from the byte array as long. {@link java.util.zip.CRC32} object.
 */
public static long getCheckSumCRC32(byte[] bytes) {
    Checksum checksum = new CRC32();
    checksum.update(bytes, 0, bytes.length);
    long cs = checksum.getValue();
    return cs;
}

From source file:net.sourceforge.jaulp.file.checksum.ChecksumUtils.java

/**
 * Gets the checksum from the given byte array with an instance of.
 *
 * @param bytes//from  w  ww  .  j a  v  a 2s  .c  om
 *            The byte array.
 * @return The checksum from the byte array as long. {@link java.util.zip.Adler32} object.
 */
public static long getCheckSumAdler32(byte[] bytes) {
    Checksum checksum = new Adler32();
    checksum.update(bytes, 0, bytes.length);
    long cs = checksum.getValue();
    return cs;
}

From source file:com.nridge.core.base.std.FilUtl.java

/**
 * Generates a unique path based on the parameters provided.
 *
 * @param aPathName Optional path name - if not provided, then the current working directory will be used.
 * @param aPrefix Path name prefix (appended with random id)
 *
 * @return A unique path name.//  ww w.  j a  v  a 2s.  co m
 */
static public String generateUniquePathName(String aPathName, String aPrefix) {
    if (StringUtils.isEmpty(aPathName))
        aPathName = getWorkingDirectory();
    if (StringUtils.isEmpty(aPathName))
        aPrefix = "subpath";

    // http://www.javapractices.com/topic/TopicAction.do?Id=56

    UUID uniqueId = UUID.randomUUID();
    byte idBytes[] = uniqueId.toString().getBytes();
    Checksum checksumValue = new CRC32();
    checksumValue.update(idBytes, 0, idBytes.length);
    long longValue = checksumValue.getValue();

    return String.format("%s%c%s_%d", aPathName, File.separatorChar, aPrefix, longValue);
}

From source file:com.nridge.core.base.std.FilUtl.java

/**
 * Generates a unique path and file name combination based on the parameters
 * provided./*from w w  w .jav a2s . c  om*/
 *
 * @param aPathName Path name.
 * @param aFilePrefix File name prefix (appended with random id)
 * @param aFileExtension File name extension.
 *
 * @return A unique path and file name combination.
 */
static public String generateUniquePathFileName(String aPathName, String aFilePrefix, String aFileExtension) {
    String pathFileName;

    if (StringUtils.isNotEmpty(aPathName))
        pathFileName = String.format("%s%c%s", aPathName, File.separatorChar, aFilePrefix);
    else
        pathFileName = aFilePrefix;

    // http://www.javapractices.com/topic/TopicAction.do?Id=56

    UUID uniqueId = UUID.randomUUID();
    byte idBytes[] = uniqueId.toString().getBytes();
    Checksum checksumValue = new CRC32();
    checksumValue.update(idBytes, 0, idBytes.length);
    long longValue = checksumValue.getValue();

    if (StringUtils.startsWith(aFileExtension, "."))
        return String.format("%s_%d%s", pathFileName, longValue, aFileExtension);
    else
        return String.format("%s_%d.%s", pathFileName, longValue, aFileExtension);
}

From source file:de.alpharogroup.file.checksum.ChecksumExtensions.java

/**
 * Gets the checksum from the given byte array with an instance of.
 *
 * @param bytes/*  w  w  w  .j a  v  a  2 s . co  m*/
 *            The byte array.
 * @return The checksum from the byte array as long. {@link java.util.zip.CRC32} object.
 */
public static long getCheckSumCRC32(final byte[] bytes) {
    final Checksum checksum = new CRC32();
    checksum.update(bytes, 0, bytes.length);
    final long cs = checksum.getValue();
    return cs;
}

From source file:de.alpharogroup.file.checksum.ChecksumExtensions.java

/**
 * Gets the checksum from the given byte array with an instance of.
 *
 * @param bytes/*from   w  w w .  j av  a2  s  .co m*/
 *            The byte array.
 * @return The checksum from the byte array as long. {@link java.util.zip.Adler32} object.
 */
public static long getCheckSumAdler32(final byte[] bytes) {
    final Checksum checksum = new Adler32();
    checksum.update(bytes, 0, bytes.length);
    final long cs = checksum.getValue();
    return cs;
}