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


Java Checksum类代码示例

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


Checksum类属于java.util.zip包,在下文中一共展示了Checksum类的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: computeCrc32

import java.util.zip.Checksum; //导入依赖的package包/类
private static String computeCrc32(final FileObject fo) throws IOException {
    final Checksum crc = new CRC32();        
    try (final InputStream in = new BufferedInputStream(fo.getInputStream())) {
        int last = -1;
        int curr;
        while ((curr = in.read()) != -1) {
            if (curr != '\n' && last == '\r') { //NOI18N
                crc.update('\n');               //NOI18N
            }
            if (curr != '\r') {                 //NOI18N
                crc.update(curr);
            }
            last = curr;
        }
        if (last == '\r') {                     //NOI18N
            crc.update('\n');                   //NOI18N
        }
    }
    int val = (int)crc.getValue();
    String hex = Integer.toHexString(val);
    while (hex.length() < 8) {
        hex = "0" + hex; // NOI18N
    }
    return hex;        
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:JWSProjectPropertiesUtils.java

示例4: 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

示例5: doBench

import java.util.zip.Checksum; //导入依赖的package包/类
private static void doBench(final List<Class<? extends Checksum>> crcs,
    final PrintStream out) throws Exception {
  final byte[] bytes = new byte[MAX_LEN];
  new Random().nextBytes(bytes);

  // Print header
  out.printf("\nPerformance Table (The unit is MB/sec; #T = #Theads)\n");

  // Warm up implementations to get jit going.
  for (Class<? extends Checksum> c : crcs) {
    doBench(c, 1, bytes, 2);
    doBench(c, 1, bytes, 2101);
  }

  // Test on a variety of sizes with different number of threads
  for (int size = 32; size <= MAX_LEN; size <<= 1) {
    doBench(crcs, bytes, size, out);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:TestPureJavaCrc32.java

示例6: ZipArchiveOutputStream

import java.util.zip.Checksum; //导入依赖的package包/类
public ZipArchiveOutputStream(OutputStream out,
                              Checksum cksum, ZipEntry e) {
  super(out, cksum);

  if (out == null) {
    throw new NullPointerException("out == null");
  }

  if (cksum == null) {
    throw new NullPointerException("cksum == null");
  }

  if (e == null) {
    throw new NullPointerException("e == null");
  }

  entry = e;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:19,代码来源:ZipArchive.java

示例7: createIndexFile

import java.util.zip.Checksum; //导入依赖的package包/类
private static void createIndexFile(File indexFile, Configuration conf)
    throws IOException {
  if (indexFile.exists()) {
    System.out.println("Deleting existing file");
    indexFile.delete();
  }
  indexFile.createNewFile();
  FSDataOutputStream output = FileSystem.getLocal(conf).getRaw().append(
      new Path(indexFile.getAbsolutePath()));
  Checksum crc = new PureJavaCrc32();
  crc.reset();
  CheckedOutputStream chk = new CheckedOutputStream(output, crc);
  String msg = "Writing new index file. This file will be used only " +
      "for the testing.";
  chk.write(Arrays.copyOf(msg.getBytes(),
      MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH));
  output.writeLong(chk.getChecksum().getValue());
  output.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestShuffleHandler.java

示例8: testUpdate

import java.util.zip.Checksum; //导入依赖的package包/类
@Test
public void testUpdate() {
    final byte[] bytes = "Any String you want".getBytes();
    final int len = bytes.length;

    Checksum crc1 = Crc32C.create();
    Checksum crc2 = Crc32C.create();
    Checksum crc3 = Crc32C.create();

    crc1.update(bytes, 0, len);
    for (int i = 0; i < len; i++)
        crc2.update(bytes[i]);
    crc3.update(bytes, 0, len / 2);
    crc3.update(bytes, len / 2, len - len / 2);

    assertEquals("Crc values should be the same", crc1.getValue(), crc2.getValue());
    assertEquals("Crc values should be the same", crc1.getValue(), crc3.getValue());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:Crc32CTest.java

示例9: updateChecksumInt

import java.util.zip.Checksum; //导入依赖的package包/类
public static void updateChecksumInt(Checksum checksum, int v)
{
    checksum.update((v >>> 24) & 0xFF);
    checksum.update((v >>> 16) & 0xFF);
    checksum.update((v >>> 8) & 0xFF);
    checksum.update((v >>> 0) & 0xFF);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:8,代码来源:FBUtilities.java

示例10: newInstance

import java.util.zip.Checksum; //导入依赖的package包/类
/**
 * Create a new instance of a Checksum object.
 * @return The newly created Checksum object
 */
static public Checksum newInstance(String className) throws IOException {
  try {
    Class<?> clazz = getClassByName(className);
    return (Checksum)newInstance(clazz);
  } catch (ClassNotFoundException e) {
    throw new IOException(e);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:13,代码来源:ChecksumFactory.java

示例11: testLittleEndianReadonlyByteBufferOffset

import java.util.zip.Checksum; //导入依赖的package包/类
private static void testLittleEndianReadonlyByteBufferOffset(Checksum checksum, long expected) {
    byte[] unaligned_bytes_123456789 = new byte[BYTES_123456789.length + 64];
    for (int i = 0; i < unaligned_bytes_123456789.length - BYTES_123456789.length; i++) {
        checksum.reset();
        System.arraycopy(BYTES_123456789, 0, unaligned_bytes_123456789, i, BYTES_123456789.length);
        ByteBuffer bb = ByteBuffer.wrap(unaligned_bytes_123456789).asReadOnlyBuffer();
        bb.order(ByteOrder.LITTLE_ENDIAN);
        bb.position(i);
        bb.limit(i + BYTES_123456789.length);
        checksum.update(bb);
        checkChecksumOffset(checksum, expected, i);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ChecksumBase.java

示例12: throwChecksumException

import java.util.zip.Checksum; //导入依赖的package包/类
private static void throwChecksumException(Type type, Checksum algorithm,
    String filename, long errPos, int expected, int computed)
        throws ChecksumException {
  throw new ChecksumException("Checksum " + type
      + " not matched for file " + filename + " at position "+ errPos
      + String.format(": expected=%X but computed=%X", expected, computed)
      + ", algorithm=" + algorithm.getClass().getSimpleName(), errPos);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:9,代码来源:DataChecksum.java

示例13: verifyChunked

import java.util.zip.Checksum; //导入依赖的package包/类
@Override
public void verifyChunked(ByteBuffer data, int bytesPerCrc,
    ByteBuffer crcs, String filename, long basePos)
        throws ChecksumException {
  final Checksum algorithm = newAlgorithm();
  if (data.hasArray() && crcs.hasArray()) {
    DataChecksum.verifyChunked(DataChecksum.Type.CRC32, algorithm,
        data.array(), data.position(), data.remaining(), bytesPerCrc,
        crcs.array(), crcs.position(), filename, basePos);
  } else {
    DataChecksum.verifyChunked(DataChecksum.Type.CRC32, algorithm,
        data, bytesPerCrc, crcs, filename, basePos);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:15,代码来源:Crc32PerformanceTest.java

示例14: 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:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:8,代码来源:Encoder.java

示例15: SpillRecord

import java.util.zip.Checksum; //导入依赖的package包/类
public SpillRecord(Path indexFileName, JobConf job, Checksum crc,
                   String expectedIndexOwner)
    throws IOException {

  final FileSystem rfs = FileSystem.getLocal(job).getRaw();
  final FSDataInputStream in =
      SecureIOUtils.openFSDataInputStream(new File(indexFileName.toUri()
          .getRawPath()), expectedIndexOwner, null);
  try {
    final long length = rfs.getFileStatus(indexFileName).getLen();
    final int partitions = (int) length / MAP_OUTPUT_INDEX_RECORD_LENGTH;
    final int size = partitions * MAP_OUTPUT_INDEX_RECORD_LENGTH;
    buf = ByteBuffer.allocate(size);
    if (crc != null) {
      crc.reset();
      CheckedInputStream chk = new CheckedInputStream(in, crc);
      IOUtils.readFully(chk, buf.array(), 0, size);
      
      if (chk.getChecksum().getValue() != in.readLong()) {
        throw new ChecksumException("Checksum error reading spill index: " +
                              indexFileName, -1);
      }
    } else {
      IOUtils.readFully(in, buf.array(), 0, size);
    }
    entries = buf.asLongBuffer();
  } finally {
    in.close();
  }
}
 
开发者ID:intel-hpdd,项目名称:lustre-connector-for-hadoop,代码行数:31,代码来源:SharedFsPlugins.java


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