List of usage examples for java.util.zip Adler32 getValue
@Override public long getValue()
From source file:org.anarres.lzo.LzopOutputStream.java
/** * Writes an lzop-compatible header to the OutputStream provided. *///from w ww . j a va 2s. co m protected void writeLzopHeader() throws IOException { DataOutputBuffer dob = new DataOutputBuffer(); try { dob.writeShort(LzopConstants.LZOP_VERSION); dob.writeShort(LzoVersion.LZO_LIBRARY_VERSION); dob.writeShort(LzopConstants.LZOP_COMPAT_VERSION); switch (getAlgorithm()) { case LZO1X: // case LZO1X_1: dob.writeByte(LzopConstants.M_LZO1X_1); dob.writeByte(5); break; /* case LZO1X_15: dob.writeByte(LzopConstants.M_LZO1X_1_15); dob.writeByte(1); break; case LZO1X_999: dob.writeByte(LzopConstants.M_LZO1X_999); dob.writeByte(9); break; */ default: throw new IOException("Incompatible lzop algorithm " + getAlgorithm()); } long mask = LzopConstants.F_ADLER32_C | LzopConstants.F_ADLER32_D; mask = mask | LzopConstants.F_CRC32_C | LzopConstants.F_CRC32_D; dob.writeInt((int) (flags & mask & 0xFFFFFFFF)); // all flags 0 dob.writeInt(33188); // mode dob.writeInt((int) (System.currentTimeMillis() / 1000)); // mtime dob.writeInt(0); // gmtdiff ignored dob.writeByte(0); // no filename Adler32 headerChecksum = new Adler32(); headerChecksum.update(dob.getData(), 0, dob.getLength()); int hc = (int) headerChecksum.getValue(); dob.writeInt(hc); out.write(LzopConstants.LZOP_MAGIC); out.write(dob.getData(), 0, dob.getLength()); } finally { dob.close(); } }
From source file:org.olat.upgrade.OLATUpgrade_9_0_0.java
private long checksum(byte[] binaryDatas) throws IOException { InputStream in = null;/* w w w . ja v a2 s . co m*/ Adler32 checksum = new Adler32(); try { in = new CheckedInputStream(new ByteArrayInputStream(binaryDatas), checksum); IOUtils.copy(in, new NullOutputStream()); } finally { IOUtils.closeQuietly(in); } return checksum.getValue(); }
From source file:org.pentaho.di.trans.steps.checksum.CheckSum.java
private Long calculCheckSum(Object[] r) throws Exception { Long retval;/*from w ww. j a v a 2 s.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; }