Example usage for java.util.zip Checksum getValue

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

Introduction

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

Prototype

public long getValue();

Source Link

Document

Returns the current checksum value.

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 . j  av  a2s .  c  o m
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileInputStream fin = new FileInputStream("a.zip");
    Checksum cs = new CRC32();
    for (int b = fin.read(); b != -1; b = fin.read()) {
        cs.update(b);//  www  . j a  v  a 2s  .c  o m
    }
    System.out.println(cs.getValue());
    fin.close();
}

From source file:Main.java

public static long getCRC32(InputStream in) throws IOException {
    Checksum cs = new CRC32();

    for (int b = in.read(); b != -1; b = in.read()) {
        cs.update(b);//from  w w w  .j av  a  2s. co m
    }
    return cs.getValue();
}

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:MainClass.java

public static long getCRC32(InputStream in) throws IOException {

    Checksum cs = new CRC32();

    // more efficient to read chunks of data at a time
    for (int b = in.read(); b != -1; b = in.read()) {
        cs.update(b);//ww  w .j  a  v  a2 s  . c om
    }
    return cs.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//from w w w. jav a 2s .co 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/*  w  w w.j  a v  a2  s  .  c o m*/
 *            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.//  w  w  w.  j a va 2 s .c  o  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);
}