当前位置: 首页>>代码示例>>Java>>正文


Java Checksum.getValue方法代码示例

本文整理汇总了Java中java.util.zip.Checksum.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Checksum.getValue方法的具体用法?Java Checksum.getValue怎么用?Java Checksum.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.Checksum的用法示例。


在下文中一共展示了Checksum.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calCrc32

import java.util.zip.Checksum; //导入方法依赖的package包/类
public static byte[] calCrc32(byte[] data) {
    Checksum checksum = new CRC32();
    // update the current checksum with the specified array of bytes
    checksum.update(data, 0, data.length);

    // get the current checksum value
    long checksumValue = checksum.getValue();

    String hex = Long.toHexString(checksumValue).toUpperCase();
    while (hex.length() < 8) {
        hex = "0" + hex;
    }
    byte[] crc32 = Hex.decode(hex);

    inverseBytes(crc32);
    reverseArray(crc32);
    return crc32;
}
 
开发者ID:identiv,项目名称:ts-cards,代码行数:19,代码来源:DesfireUtils.java

示例2: computeCrc32

import java.util.zip.Checksum; //导入方法依赖的package包/类
/**
 * Compute the CRC-32 of the contents of a stream.
 * \r\n and \r are both normalized to \n for purposes of the calculation.
 */
static String computeCrc32(InputStream is) throws IOException {
    Checksum crc = new CRC32();
    int last = -1;
    int curr;
    while ((curr = is.read()) != -1) {
        if (curr != '\n' && last == '\r') {
            crc.update('\n');
        }
        if (curr != '\r') {
            crc.update(curr);
        }
        last = curr;
    }
    if (last == '\r') {
        crc.update('\n');
    }
    int val = (int)crc.getValue();
    String hex = Integer.toHexString(val);
    while (hex.length() < 8) {
        hex = "0" + hex; // NOI18N
    }
    return hex;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:GeneratedFilesHelper.java

示例3: crc32

import java.util.zip.Checksum; //导入方法依赖的package包/类
/**
 * Generates a CRC 32 Value of String passed
 *
 * @param data
 * @return long crc32 value of input. -1 if string is null
 * @throws RuntimeException if UTF-8 is not a supported character set
 */
public static long crc32(String data) {
	if (data == null) {
		return -1;
	}

	try {
		// get bytes from string
		byte bytes[] = data.getBytes("UTF-8");
		Checksum checksum = new CRC32();
		// update the current checksum with the specified array of bytes
		checksum.update(bytes, 0, bytes.length);
		// get the current checksum value
		return checksum.getValue();
	} catch (UnsupportedEncodingException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:25,代码来源:SSLUtil.java

示例4: checkChecksum

import java.util.zip.Checksum; //导入方法依赖的package包/类
private static void checkChecksum(Checksum checksum, long expected) {
    if (checksum.getValue() != expected) {
        throw new RuntimeException("Calculated checksum result was invalid."
                + " Expected " + Long.toHexString(expected)
                + ", but got " + Long.toHexString(checksum.getValue()) + ".");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:ChecksumBase.java

示例5: checkChecksumOffset

import java.util.zip.Checksum; //导入方法依赖的package包/类
private static void checkChecksumOffset(Checksum checksum, long expected, int offset) {
    if (checksum.getValue() != expected) {
        throw new RuntimeException("Calculated CRC32C result was invalid. Array offset "
                + offset + ". Expected: " + Long.toHexString(expected) + ", Got: "
                + Long.toHexString(checksum.getValue()));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:ChecksumBase.java

示例6: crc32

import java.util.zip.Checksum; //导入方法依赖的package包/类
public Encoder crc32() {
    Checksum checksum = new CRC32();
    checksum.update(data, 0, data.length);
    long checksumValue = checksum.getValue();
    data = Long.toHexString(checksumValue).getBytes();
    return unhex();
}
 
开发者ID:lorderikir,项目名称:googlecloud-techtalk,代码行数:8,代码来源:Encoder.java

示例7: assertChecksum

import java.util.zip.Checksum; //导入方法依赖的package包/类
private static void assertChecksum(Supplier<Checksum> supplier, String input) {
  byte[] bytes = HashTestUtils.ascii(input);

  Checksum checksum = supplier.get();
  checksum.update(bytes, 0, bytes.length);
  long value = checksum.getValue();

  String toString = "name";
  HashFunction func = new ChecksumHashFunction(supplier, 32, toString);
  assertEquals(toString, func.toString());
  assertEquals(value, func.hashBytes(bytes).padToLong());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:13,代码来源:ChecksumHashFunctionTest.java

示例8: check

import java.util.zip.Checksum; //导入方法依赖的package包/类
private static void check(Checksum crc1, Checksum crc2) throws Exception {
    if (crc1.getValue() != crc2.getValue()) {
        String s = "value 1 = " + crc1.getValue() + ", value 2 = " + crc2.getValue();
        System.err.println(s);
        throw new Exception(s);
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:8,代码来源:CRCTest.java

示例9: validateChecksum

import java.util.zip.Checksum; //导入方法依赖的package包/类
/**
 * Validate a transaction's checksum
 */
private void validateChecksum(DataInputStream in,
                              Checksum checksum,
                              long txid)
    throws IOException {
  if (checksum != null) {
    int calculatedChecksum = (int)checksum.getValue();
    int readChecksum = in.readInt(); // read in checksum
    if (readChecksum != calculatedChecksum) {
      throw new ChecksumException(
          "Transaction is corrupt. Calculated checksum is " +
          calculatedChecksum + " but read checksum " + readChecksum, txid);
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:FSEditLogOp.java

示例10: computePartialChecksum

import java.util.zip.Checksum; //导入方法依赖的package包/类
public static long computePartialChecksum(long timestamp, int serializedKeySize, int serializedValueSize) {
    Checksum checksum = Crc32C.create();
    Checksums.updateLong(checksum, timestamp);
    Checksums.updateInt(checksum, serializedKeySize);
    Checksums.updateInt(checksum, serializedValueSize);
    return checksum.getValue();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:8,代码来源:DefaultRecord.java

示例11: main

import java.util.zip.Checksum; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("USAGE: LogFormatter log_file");
        System.exit(2);
    }
    FileInputStream fis = new FileInputStream(args[0]);
    BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");

    if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
        System.err.println("Invalid magic number for " + args[0]);
        System.exit(2);
    }
    System.out.println("ZooKeeper Transactional Log File with dbid "
            + fhdr.getDbid() + " txnlog format version "
            + fhdr.getVersion());

    int count = 0;
    while (true) {
        long crcValue;
        byte[] bytes;
        try {
            crcValue = logStream.readLong("crcvalue");

            bytes = logStream.readBuffer("txnEntry");
        } catch (EOFException e) {
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        Checksum crc = new Adler32();
        crc.update(bytes, 0, bytes.length);
        if (crcValue != crc.getValue()) {
            throw new IOException("CRC doesn't match " + crcValue +
                    " vs " + crc.getValue());
        }
        TxnHeader hdr = new TxnHeader();
        Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
        System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(hdr.getTime()))
                + " session 0x"
                + Long.toHexString(hdr.getClientId())
                + " cxid 0x"
                + Long.toHexString(hdr.getCxid())
                + " zxid 0x"
                + Long.toHexString(hdr.getZxid())
                + " " + TraceFormatter.op2String(hdr.getType()) + " " + txn);
        if (logStream.readByte("EOR") != 'B') {
            LOG.error("Last transaction was partial.");
            throw new EOFException("Last transaction was partial.");
        }
        count++;
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:64,代码来源:LogFormatter.java

示例12: TxnLogSource

import java.util.zip.Checksum; //导入方法依赖的package包/类
public TxnLogSource(String file) throws IOException {
this.file = file;

skiplist = new LogSkipList();

RandomAccessFileReader reader = new RandomAccessFileReader(new File(file));
try {
    BinaryInputArchive logStream = new BinaryInputArchive(reader);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");
    
    byte[] bytes = null;
    while (true) {
	long lastFp = reader.getPosition();

	long crcValue;

	try {
	    crcValue = logStream.readLong("crcvalue");
	    bytes = logStream.readBuffer("txnEntry");
	} catch (EOFException e) {
	    break;
	}
	
	if (bytes.length == 0) {
	    break;
	}
	Checksum crc = new Adler32();
	crc.update(bytes, 0, bytes.length);
	if (crcValue != crc.getValue()) {
	    throw new IOException("CRC doesn't match " + crcValue +
				  " vs " + crc.getValue());
	}
	if (logStream.readByte("EOR") != 'B') {
	    throw new EOFException("Last transaction was partial.");
	}
	TxnHeader hdr = new TxnHeader();
	Record r = SerializeUtils.deserializeTxn(bytes, hdr);
	
	if (starttime == 0) {
	    starttime = hdr.getTime();
	}
	endtime = hdr.getTime();

	if (size % skipN == 0) {
	    skiplist.addMark(hdr.getTime(), lastFp, size);
	}
	size++;
    }
    if (bytes == null) {
	throw new IOException("Nothing read from ("+file+")");
    }
} finally {
    reader.close();
}
   }
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:57,代码来源:TxnLogSource.java

示例13: updateSerialSlow

import java.util.zip.Checksum; //导入方法依赖的package包/类
private static void updateSerialSlow(Checksum crc, byte[] b, int start, int length) {
    for (int i = 0; i < length; i++)
        crc.update(b[i+start]);
    crc.getValue();
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:6,代码来源:CRCTest.java

示例14: computePartialChunkCrc

import java.util.zip.Checksum; //导入方法依赖的package包/类
/**
 * reads in the partial crc chunk and computes checksum
 * of pre-existing data in partial chunk.
 */
private Checksum computePartialChunkCrc(long blkoff, long ckoff)
    throws IOException {

  // find offset of the beginning of partial chunk.
  //
  int sizePartialChunk = (int) (blkoff % bytesPerChecksum);
  blkoff = blkoff - sizePartialChunk;
  if (LOG.isDebugEnabled()) {
    LOG.debug("computePartialChunkCrc for " + block
        + ": sizePartialChunk=" + sizePartialChunk
        + ", block offset=" + blkoff
        + ", metafile offset=" + ckoff);
  }

  // create an input stream from the block file
  // and read in partial crc chunk into temporary buffer
  //
  byte[] buf = new byte[sizePartialChunk];
  byte[] crcbuf = new byte[checksumSize];
  try (ReplicaInputStreams instr =
      datanode.data.getTmpInputStreams(block, blkoff, ckoff)) {
    IOUtils.readFully(instr.getDataIn(), buf, 0, sizePartialChunk);

    // open meta file and read in crc value computer earlier
    IOUtils.readFully(instr.getChecksumIn(), crcbuf, 0, crcbuf.length);
  }

  // compute crc of partial chunk from data read in the block file.
  final Checksum partialCrc = DataChecksum.newDataChecksum(
      diskChecksum.getChecksumType(), diskChecksum.getBytesPerChecksum());
  partialCrc.update(buf, 0, sizePartialChunk);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Read in partial CRC chunk from disk for " + block);
  }

  // paranoia! verify that the pre-computed crc matches what we
  // recalculated just now
  if (partialCrc.getValue() != checksum2long(crcbuf)) {
    String msg = "Partial CRC " + partialCrc.getValue() +
                 " does not match value computed the " +
                 " last time file was closed " +
                 checksum2long(crcbuf);
    throw new IOException(msg);
  }
  return partialCrc;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:51,代码来源:BlockReceiver.java

示例15: compute

import java.util.zip.Checksum; //导入方法依赖的package包/类
/**
 * Compute the CRC32C (Castagnoli) of the segment of the byte array given by the specified size and offset
 *
 * @param bytes The bytes to checksum
 * @param offset the offset at which to begin the checksum computation
 * @param size the number of bytes to checksum
 * @return The CRC32C
 */
public static long compute(byte[] bytes, int offset, int size) {
    Checksum crc = create();
    crc.update(bytes, offset, size);
    return crc.getValue();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:Crc32C.java


注:本文中的java.util.zip.Checksum.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。