Example usage for java.util.zip Adler32 Adler32

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

Introduction

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

Prototype

public Adler32() 

Source Link

Document

Creates a new Adler32 object.

Usage

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

/**
 * Gets the checksum from the given file. If the flag crc is true than the CheckedInputStream is
 * constructed with an instance of <code>java.util.zip.CRC32</code> otherwise with an instance
 * of <code>java.util.zip.Adler32</code>.
 *
 * @param file//from ww w. java  2s. co  m
 *            The file The file from what to get the checksum.
 * @param crc
 *            The crc If the flag crc is true than the CheckedInputStream is constructed with an
 *            instance of {@link java.util.zip.CRC32} object otherwise it is constructed with an
 *            instance of
 * @return The checksum from the given file as long.
 * @throws FileNotFoundException
 *             Is thrown if the file is not found.
 * @throws IOException
 *             Signals that an I/O exception has occurred. {@link java.util.zip.CRC32} object
 *             otherwise it is constructed with an instance of {@link java.util.zip.Adler32}
 *             object. {@link java.util.zip.Adler32} object.
 */
public static long getChecksum(final File file, final boolean crc) throws FileNotFoundException, IOException {
    CheckedInputStream cis = null;
    if (crc) {
        cis = new CheckedInputStream(new FileInputStream(file), new CRC32());
    } else {
        cis = new CheckedInputStream(new FileInputStream(file), new Adler32());
    }
    final int length = (int) file.length();
    final byte[] buffer = new byte[length];
    long checksum = 0;
    while (cis.read(buffer) >= 0) {
        checksum = cis.getChecksum().getValue();
    }
    checksum = cis.getChecksum().getValue();
    StreamExtensions.closeInputStream(cis);
    return checksum;
}

From source file:org.spliffy.server.apps.calendar.CalendarManager.java

private void updateCtag(CalEvent event) {
    OutputStream nulOut = new NullOutputStream();
    CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32());
    HashUtils.appendLine(event.getDescription(), cout);
    HashUtils.appendLine(event.getSummary(), cout);
    HashUtils.appendLine(event.getTimezone(), cout);
    HashUtils.appendLine(event.getStartDate(), cout);
    HashUtils.appendLine(event.getEndDate(), cout);
    Checksum check = cout.getChecksum();
    long crc = check.getValue();
    event.setCtag(crc);//from   w w w .  j a  v  a2 s . c  o m
    updateCtag(event.getCalendar());
}

From source file:io.milton.cloud.server.apps.calendar.CalendarManager.java

private void updateCtag(CalEvent event) {
    OutputStream nulOut = new NullOutputStream();
    CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32());
    appendLine(event.getDescription(), cout);
    appendLine(event.getSummary(), cout);
    appendLine(event.getTimezone(), cout);
    appendLine(event.getStartDate(), cout);
    appendLine(event.getEndDate(), cout);
    Checksum check = cout.getChecksum();
    long crc = check.getValue();
    event.setCtag(crc);/*from  ww w .  java  2 s. c  o  m*/
    updateCtag(event.getCalendar());
}

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

private Long calculCheckSum(Object[] r) throws Exception {
    Long retval;//  w  ww  .  j  a v a2s  .co m
    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;
}

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 v  a2  s.  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:org.spliffy.server.apps.calendar.CalendarManager.java

private void updateCtag(Calendar sourceCal) {
    OutputStream nulOut = new NullOutputStream();
    CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32());

    HashUtils.appendLine(sourceCal.getColor(), cout);
    if (sourceCal.getEvents() != null) {
        for (CalEvent r : sourceCal.getEvents()) {
            String name = r.getName();
            String line = HashUtils.toHashableText(name, r.getCtag(), "");
            HashUtils.appendLine(line, cout);
        }//ww  w. j  a  va  2  s. c o  m
    }
    Checksum check = cout.getChecksum();
    long crc = check.getValue();
    sourceCal.setCtag(crc);
}

From source file:io.milton.cloud.server.apps.calendar.CalendarManager.java

private void updateCtag(Calendar sourceCal) {
    OutputStream nulOut = new NullOutputStream();
    CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32());

    appendLine(sourceCal.getColor(), cout);
    if (sourceCal.getEvents() != null) {
        for (CalEvent r : sourceCal.getEvents()) {
            String name = r.getName();
            String line = HashCalc.getInstance().toHashableText(name, r.getCtag() + "", "");
            appendLine(line, cout);//  w  ww .  j a v a2  s  .co m
        }
    }
    Checksum check = cout.getChecksum();
    long crc = check.getValue();
    sourceCal.setCtag(crc);
}

From source file:org.theospi.portfolio.guidance.impl.GuidanceManagerImpl.java

public void packageGuidanceForExport(List guidanceIds, OutputStream os) throws IOException {
    CheckedOutputStream checksum = new CheckedOutputStream(os, new Adler32());
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum));
    List exportedRefs = new ArrayList();
    for (Iterator i = guidanceIds.iterator(); i.hasNext();) {
        String id = (String) i.next();
        processGuidance(id, zos, exportedRefs);
    }/*from  w  w w.  j ava  2s.  co m*/

    zos.finish();
    zos.flush();
}

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 av  a  2  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(final byte[] bytes) {
    final Checksum checksum = new Adler32();
    checksum.update(bytes, 0, bytes.length);
    final long cs = checksum.getValue();
    return cs;
}

From source file:com.alcatel_lucent.nz.wnmsextract.reader.FileUtilities.java

public long checksum(File input) {
    long checksum = -1;
    try {//  ww w.  j a  va  2  s.  co m
        FileInputStream fis = null;
        CheckedInputStream cis = null;
        Adler32 adler = null;
        fis = new FileInputStream(input);
        adler = new Adler32();
        cis = new CheckedInputStream(fis, adler);

        byte[] buffer = new byte[1024];
        while (cis.read(buffer) >= 0) {
            checksum = cis.getChecksum().getValue();
        }

    } catch (IOException e) {
        jlog.fatal("IO Exception on " + input.getAbsolutePath() + e);
    }

    return checksum;

}