Here are the examples of the java api class java.util.zip.CRC32 taken from open source projects.
1. CAFS#checksum()
Project: bnd
File: CAFS.java
File: CAFS.java
short checksum(int flags, int compressedLength, int totalLength, byte[] sha1) { CRC32 crc = new CRC32(); crc.update(flags); crc.update(flags >> 8); crc.update(flags >> 16); crc.update(flags >> 24); crc.update(compressedLength); crc.update(compressedLength >> 8); crc.update(compressedLength >> 16); crc.update(compressedLength >> 24); crc.update(totalLength); crc.update(totalLength >> 8); crc.update(totalLength >> 16); crc.update(totalLength >> 24); crc.update(sha1); return (short) crc.getValue(); }
2. CRC32Test#test_update$B()
Project: j2objc
File: CRC32Test.java
File: CRC32Test.java
/** * @tests java.util.zip.CRC32#update(byte[]) */ public void test_update$B() { // test methods of java.util.zip.crc32.update(byte[]) byte byteArray[] = { 1, 2 }; CRC32 crc = new CRC32(); crc.update(byteArray); // System.out.print("value of crc"+crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 3066839698 assertEquals("update(byte[]) failed to update the checksum to the correct value ", 3066839698L, crc.getValue()); crc.reset(); byte byteEmpty[] = new byte[10000]; crc.update(byteEmpty); // System.out.print("value of crc"+crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 1295764014 assertEquals("update(byte[]) failed to update the checksum to the correct value ", 1295764014L, crc.getValue()); }
3. CRC32Test#test_reset()
Project: j2objc
File: CRC32Test.java
File: CRC32Test.java
/** * @tests java.util.zip.CRC32#reset() */ public void test_reset() { // test methods of java.util.zip.crc32.reset() CRC32 crc = new CRC32(); crc.update(1); // System.out.print("value of crc"+crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 2768625435 assertEquals("update(int) failed to update the checksum to the correct value ", 2768625435L, crc.getValue()); crc.reset(); assertEquals("reset failed to reset the checksum value to zero", 0, crc.getValue()); }
4. OldAndroidChecksumTest#cRC32Test()
Project: j2objc
File: OldAndroidChecksumTest.java
File: OldAndroidChecksumTest.java
private void cRC32Test(byte[] values, long expected) { CRC32 crc = new CRC32(); // try it all at once crc.update(values); assertEquals(crc.getValue(), expected); // try resetting and computing one byte at a time crc.reset(); for (int i = 0; i < values.length; i++) { crc.update(values[i]); } assertEquals(crc.getValue(), expected); }
5. ZipUtils#getCrc()
Project: igv
File: ZipUtils.java
File: ZipUtils.java
private static long getCrc(File file) throws IOException { CRC32 crc = new CRC32(); crc.reset(); byte[] buffer = new byte[1024]; int bytesRead = 0; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); while ((bytesRead = bis.read(buffer)) != -1) { crc.update(buffer, 0, bytesRead); } bis.close(); return crc.getValue(); }
6. TestRaidDfs#createTestFilePartialLastBlock()
Project: hadoop-20
File: TestRaidDfs.java
File: TestRaidDfs.java
// // Creates a file with partially full last block. Populate it with random // data. Returns its crc. // public static long createTestFilePartialLastBlock(FileSystem fileSys, Path name, int repl, int numBlocks, long blocksize) throws IOException { CRC32 crc = new CRC32(); Random rand = new Random(); FSDataOutputStream stm = fileSys.create(name, true, fileSys.getConf().getInt("io.file.buffer.size", 4096), (short) repl, blocksize); // Write whole blocks. byte[] b = new byte[(int) blocksize]; for (int i = 1; i < numBlocks; i++) { rand.nextBytes(b); stm.write(b); crc.update(b); } // Write partial block. b = new byte[(int) blocksize / 2 - 1]; rand.nextBytes(b); stm.write(b); crc.update(b); stm.close(); return crc.getValue(); }
7. BaseDirectoryTestCase#testChecksum()
Project: lucene-solr
File: BaseDirectoryTestCase.java
File: BaseDirectoryTestCase.java
// TODO: fold in some of the testing of o.a.l.index.TestIndexInput in here! public void testChecksum() throws Exception { CRC32 expected = new CRC32(); int numBytes = random().nextInt(20000); byte bytes[] = new byte[numBytes]; random().nextBytes(bytes); expected.update(bytes); Directory dir = getDirectory(createTempDir("testChecksum")); IndexOutput output = dir.createOutput("checksum", newIOContext(random())); output.writeBytes(bytes, 0, bytes.length); output.close(); ChecksumIndexInput input = dir.openChecksumInput("checksum", newIOContext(random())); input.skipBytes(numBytes); assertEquals(expected.getValue(), input.getChecksum()); input.close(); dir.close(); }
8. NrpePacket#encode()
Project: zorka
File: NrpePacket.java
File: NrpePacket.java
/** * Encodes packet and writes it to output stream. * * @param os output stream * * @throws IOException when I/O error occurs */ public void encode(OutputStream os) throws IOException { ByteBuffer bb = ByteBuffer.allocate(10).order(ByteOrder.BIG_ENDIAN); bb.putShort((short) version).putShort((short) type).putInt(0).putShort((short) resultCode); byte[] msg = data.getBytes(); byte[] pkt = new byte[1036]; System.arraycopy(bb.array(), 0, pkt, 0, 10); System.arraycopy(msg, 0, pkt, 10, msg.length); CRC32 crc = new CRC32(); crc.update(pkt); byte[] crc32 = ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(crc.getValue()).array(); System.arraycopy(crc32, 4, pkt, 4, 4); pkt[pkt.length - 1] = '\0'; os.write(pkt); }
9. ZicoConnector#send()
Project: zorka
File: ZicoConnector.java
File: ZicoConnector.java
/** * Sends packet of given type. * * @param type packet type * @param data data (bytes) * @throws IOException when network error occurs. */ public void send(int type, byte... data) throws IOException { CRC32 crc = new CRC32(); crc.update(data); for (int i : ZICO_MAGIC) { out.write(i); } byte[] b = new byte[HEADER_LENGTH]; ByteBuffer buf = ByteBuffer.wrap(b); buf.putShort((short) type); buf.putInt(data.length); buf.putLong(crc.getValue()); out.write(b); if (data.length > 0) { out.write(data); } }
10. AbstractMessageSetEncoder#computeCRC32()
Project: weave
File: AbstractMessageSetEncoder.java
File: AbstractMessageSetEncoder.java
protected final int computeCRC32(ChannelBuffer buffer) { CRC32 crc32 = CRC32_LOCAL.get(); crc32.reset(); if (buffer.hasArray()) { crc32.update(buffer.array(), buffer.arrayOffset() + buffer.readerIndex(), buffer.readableBytes()); } else { byte[] bytes = new byte[buffer.readableBytes()]; buffer.getBytes(buffer.readerIndex(), bytes); crc32.update(bytes); } return (int) crc32.getValue(); }
11. FileHashHelper#crc32Hash()
Project: vsts-authentication-library-for-java
File: FileHashHelper.java
File: FileHashHelper.java
/** * Calculate CRC32 hash of a given input stream. * * Warning: CRC32 is not a secure hash algorithm. * * @param is a stream of bytes * @return CRC32 hash of this stream * @throws IOException */ public static long crc32Hash(final InputStream is) throws IOException { if (is == null) { throw new IOException("InputStream is null."); } final CRC32 crcMaker = new CRC32(); final byte[] buffer = new byte[65536]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { crcMaker.update(buffer, 0, bytesRead); } return crcMaker.getValue(); }
12. getCRCFromRep#run()
Project: voltdb
File: getCRCFromRep.java
File: getCRCFromRep.java
public long run(int id) { CRC32 crc = new CRC32(); voltQueueSQL(Stmt, id); VoltTable[] result = voltExecuteSQL(true); while (result[0].advanceRow()) { long counter = result[0].getLong("counter"); byte[] b = new byte[8]; for (int i = 0; i < 8; i++) { b[7 - i] = (byte) (counter >>> (i * 8)); } crc.update(b); } return crc.getValue(); }
13. getCRCFromPtn#run()
Project: voltdb
File: getCRCFromPtn.java
File: getCRCFromPtn.java
public long run(int id) { CRC32 crc = new CRC32(); voltQueueSQL(Stmt, id); VoltTable[] result = voltExecuteSQL(true); while (result[0].advanceRow()) { long counter = result[0].getLong("counter"); byte[] b = new byte[8]; for (int i = 0; i < 8; i++) { b[7 - i] = (byte) (counter >>> (i * 8)); } crc.update(b); } return crc.getValue(); }
14. PageStore#writeVariableHeader()
Project: ThriftyPaxos
File: PageStore.java
File: PageStore.java
private void writeVariableHeader() { trace.debug("writeVariableHeader"); if (logMode == LOG_MODE_SYNC) { file.sync(); } Data page = createData(); page.writeInt(0); page.writeLong(getWriteCountTotal()); page.writeInt(logKey); page.writeInt(logFirstTrunkPage); page.writeInt(logFirstDataPage); CRC32 crc = new CRC32(); crc.update(page.getBytes(), 4, pageSize - 4); page.setInt(0, (int) crc.getValue()); file.seek(pageSize); file.write(page.getBytes(), 0, pageSize); file.seek(pageSize + pageSize); file.write(page.getBytes(), 0, pageSize); // don't increment the write counter, because it was just written }
15. SerializeG#dumpinfo()
Project: spring-loaded
File: SerializeG.java
File: SerializeG.java
private static void dumpinfo(byte[] bytes) { CRC32 crc = new CRC32(); crc.update(bytes, 0, bytes.length); StringBuilder data = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { int val = bytes[i]; String s = "00" + Integer.toHexString(val); data.append(s.substring(s.length() - 2)); } System.out.println("Bytedata:" + data.toString()); System.out.println("byteinfo:len=" + bytes.length + ":crc=" + Long.toHexString(crc.getValue())); // when run directly, this will print: byteinfo:len=98:crc=c1047cf6 }
16. Serialize#dumpinfo()
Project: spring-loaded
File: Serialize.java
File: Serialize.java
private void dumpinfo(byte[] bytes) { CRC32 crc = new CRC32(); crc.update(bytes, 0, bytes.length); StringBuilder data = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { int val = bytes[i]; String s = "00" + Integer.toHexString(val); data.append(s.substring(s.length() - 2)); } System.out.println("Bytedata:" + data.toString()); System.out.println("byteinfo:len=" + bytes.length + ":crc=" + Long.toHexString(crc.getValue())); // when run directly, this will print: byteinfo:len=98:crc=c1047cf6 }
17. WarLauncherTests#createWarArchive()
Project: spring-boot
File: WarLauncherTests.java
File: WarLauncherTests.java
private File createWarArchive() throws IOException, FileNotFoundException { File warRoot = new File("target/archive.war"); warRoot.delete(); JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(warRoot)); jarOutputStream.putNextEntry(new JarEntry("WEB-INF/")); jarOutputStream.putNextEntry(new JarEntry("WEB-INF/classes/")); jarOutputStream.putNextEntry(new JarEntry("WEB-INF/lib/")); JarEntry webInfLibFoo = new JarEntry("WEB-INF/lib/foo.jar"); webInfLibFoo.setMethod(ZipEntry.STORED); ByteArrayOutputStream fooJarStream = new ByteArrayOutputStream(); new JarOutputStream(fooJarStream).close(); webInfLibFoo.setSize(fooJarStream.size()); CRC32 crc32 = new CRC32(); crc32.update(fooJarStream.toByteArray()); webInfLibFoo.setCrc(crc32.getValue()); jarOutputStream.putNextEntry(webInfLibFoo); jarOutputStream.write(fooJarStream.toByteArray()); jarOutputStream.close(); return warRoot; }
18. TestJarCreator#writeNestedEntry()
Project: spring-boot
File: TestJarCreator.java
File: TestJarCreator.java
private static void writeNestedEntry(String name, boolean unpackNested, JarOutputStream jarOutputStream) throws Exception, IOException { JarEntry nestedEntry = new JarEntry(name); byte[] nestedJarData = getNestedJarData(); nestedEntry.setSize(nestedJarData.length); nestedEntry.setCompressedSize(nestedJarData.length); if (unpackNested) { nestedEntry.setComment("UNPACK:0000000000000000000000000000000000000000"); } CRC32 crc32 = new CRC32(); crc32.update(nestedJarData); nestedEntry.setCrc(crc32.getValue()); nestedEntry.setMethod(ZipEntry.STORED); jarOutputStream.putNextEntry(nestedEntry); jarOutputStream.write(nestedJarData); jarOutputStream.closeEntry(); }
19. UnoPkg#getCRC32()
Project: sis
File: UnoPkg.java
File: UnoPkg.java
/** * Computes CRC32 for the given file. */ private static long getCRC32(final File file) throws IOException { final CRC32 crc = new CRC32(); final InputStream in = new FileInputStream(file); try { final byte[] buffer = new byte[4 * 1024]; int length; while ((length = in.read(buffer)) >= 0) { crc.update(buffer, 0, length); } } finally { in.close(); } return crc.getValue(); }
20. ODiskWriteAheadLog#writeMasterRecord()
Project: orientdb
File: ODiskWriteAheadLog.java
File: ODiskWriteAheadLog.java
private void writeMasterRecord(int index, OLogSequenceNumber masterRecord) throws IOException { masterRecordLSNHolder.seek(index * (OIntegerSerializer.INT_SIZE + 2 * OLongSerializer.LONG_SIZE)); final CRC32 crc32 = new CRC32(); final byte[] serializedLSN = new byte[2 * OLongSerializer.LONG_SIZE]; OLongSerializer.INSTANCE.serializeLiteral(masterRecord.getSegment(), serializedLSN, 0); OLongSerializer.INSTANCE.serializeLiteral(masterRecord.getPosition(), serializedLSN, OLongSerializer.LONG_SIZE); crc32.update(serializedLSN); masterRecordLSNHolder.writeInt((int) crc32.getValue()); masterRecordLSNHolder.writeLong(masterRecord.getSegment()); masterRecordLSNHolder.writeLong(masterRecord.getPosition()); }
21. T6836682#computeCRC()
Project: openjdk
File: T6836682.java
File: T6836682.java
static long computeCRC(File inFile) throws IOException { byte[] buffer = new byte[8192]; CRC32 crc = new CRC32(); FileInputStream fis = null; BufferedInputStream bis = null; try { fis = new FileInputStream(inFile); bis = new BufferedInputStream(fis); int n = bis.read(buffer); while (n > 0) { crc.update(buffer, 0, n); n = bis.read(buffer); } } finally { Utils.close(bis); Utils.close(fis); } return crc.getValue(); }
22. BigJar#computeCRC()
Project: openjdk
File: BigJar.java
File: BigJar.java
long computeCRC(File inFile) throws IOException { byte[] buffer = new byte[8192]; CRC32 crc = new CRC32(); try (FileInputStream fis = new FileInputStream(inFile); BufferedInputStream bis = new BufferedInputStream(fis)) { int n = bis.read(buffer); while (n > 0) { crc.update(buffer, 0, n); n = bis.read(buffer); } } return crc.getValue(); }
23. GzipSourceTest#gunzip_withHCRC()
Project: okio
File: GzipSourceTest.java
File: GzipSourceTest.java
@Test public void gunzip_withHCRC() throws Exception { CRC32 hcrc = new CRC32(); ByteString gzipHeader = gzipHeaderWithFlags((byte) 0x02); hcrc.update(gzipHeader.toByteArray()); Buffer gzipped = new Buffer(); gzipped.write(gzipHeader); // little endian gzipped.writeShort(Util.reverseBytesShort((short) hcrc.getValue())); gzipped.write(deflated); gzipped.write(gzipTrailer); assertGzipped(gzipped); }
24. DownloadController#computeCrc()
Project: libresonic
File: DownloadController.java
File: DownloadController.java
/** * Computes the CRC checksum for the given file. * * @param file The file to compute checksum for. * @return A CRC32 checksum. * @throws IOException If an I/O error occurs. */ private long computeCrc(File file) throws IOException { CRC32 crc = new CRC32(); InputStream in = new FileInputStream(file); try { byte[] buf = new byte[8192]; int n = in.read(buf); while (n != -1) { crc.update(buf, 0, n); n = in.read(buf); } } finally { in.close(); } return crc.getValue(); }
25. TarWriter#writeEntry()
Project: jackrabbit-oak
File: TarWriter.java
File: TarWriter.java
long writeEntry(long msb, long lsb, byte[] data, int offset, int size, int generation) throws IOException { checkNotNull(data); checkPositionIndexes(offset, offset + size, data.length); UUID uuid = new UUID(msb, lsb); CRC32 checksum = new CRC32(); checksum.update(data, offset, size); String entryName = String.format("%s.%08x", uuid, checksum.getValue()); byte[] header = newEntryHeader(entryName, size); log.debug("Writing segment {} to {}", uuid, file); return writeEntry(uuid, header, data, offset, size, generation); }
26. TarWriter#writeEntry()
Project: jackrabbit-oak
File: TarWriter.java
File: TarWriter.java
long writeEntry(long msb, long lsb, byte[] data, int offset, int size) throws IOException { checkNotNull(data); checkPositionIndexes(offset, offset + size, data.length); UUID uuid = new UUID(msb, lsb); CRC32 checksum = new CRC32(); checksum.update(data, offset, size); String entryName = String.format("%s.%08x", uuid, checksum.getValue()); byte[] header = newEntryHeader(entryName, size); log.debug("Writing segment {} to {}", uuid, file); return writeEntry(uuid, header, data, offset, size); }
27. IdeaWin32#loadBundledLibrary()
Project: intellij-community
File: IdeaWin32.java
File: IdeaWin32.java
private static boolean loadBundledLibrary() throws IOException { String name = SystemInfo.is64Bit ? "IdeaWin64" : "IdeaWin32"; URL bundled = IdeaWin32.class.getResource(name + ".dll"); if (bundled == null) return false; byte[] content = FileUtil.loadBytes(bundled.openStream()); CRC32 crc32 = new CRC32(); crc32.update(content); long hash = Math.abs(crc32.getValue()); File file = new File(FileUtil.getTempDirectory(), name + '.' + hash + ".dll"); if (!file.exists()) FileUtil.writeToFile(file, content); System.load(file.getPath()); return true; }
28. GridDiscoveryManager#topologyHash()
Project: ignite
File: GridDiscoveryManager.java
File: GridDiscoveryManager.java
/** * Gets topology hash for given set of nodes. * * @param nodes Subset of grid nodes for hashing. * @return Hash for given topology. */ public long topologyHash(Iterable<? extends ClusterNode> nodes) { assert nodes != null; Iterator<? extends ClusterNode> iter = nodes.iterator(); if (!iter.hasNext()) // Special case. return 0; List<String> uids = new ArrayList<>(); for (ClusterNode node : nodes) uids.add(node.id().toString()); Collections.sort(uids); CRC32 hash = new CRC32(); for (String uuid : uids) hash.update(uuid.getBytes()); return hash.getValue(); }
29. TestLookasideCache#createTestFile()
Project: hadoop-20
File: TestLookasideCache.java
File: TestLookasideCache.java
// // creates a file and populate it with random data. Returns its crc. // private static long createTestFile(FileSystem fileSys, Path name, int repl, int numBlocks, long blocksize) throws IOException { CRC32 crc = new CRC32(); Random rand = new Random(); FSDataOutputStream stm = fileSys.create(name, true, fileSys.getConf().getInt("io.file.buffer.size", 4096), (short) repl, blocksize); // fill random data into file final byte[] b = new byte[(int) blocksize]; for (int i = 0; i < numBlocks; i++) { rand.nextBytes(b); stm.write(b); crc.update(b); } stm.close(); return crc.getValue(); }
30. TestStatisticsCollector#createFile()
Project: hadoop-20
File: TestStatisticsCollector.java
File: TestStatisticsCollector.java
private static long createFile(FileSystem fileSys, Path name, int repl, int numBlocks, long blocksize) throws IOException { CRC32 crc = new CRC32(); int bufSize = fileSys.getConf().getInt("io.file.buffer.size", 4096); FSDataOutputStream stm = fileSys.create(name, true, bufSize, (short) repl, blocksize); // fill random data into file byte[] b = new byte[(int) blocksize]; for (int i = 0; i < numBlocks; i++) { rand.nextBytes(b); stm.write(b); crc.update(b); } stm.close(); return crc.getValue(); }
31. TestRaidNode#createOldFile()
Project: hadoop-20
File: TestRaidNode.java
File: TestRaidNode.java
// // creates a file and populate it with random data. Returns its crc. // static long createOldFile(FileSystem fileSys, Path name, int repl, int numBlocks, long blocksize) throws IOException { CRC32 crc = new CRC32(); FSDataOutputStream stm = fileSys.create(name, true, fileSys.getConf().getInt("io.file.buffer.size", 4096), (short) repl, blocksize); // fill random data into file byte[] b = new byte[(int) blocksize]; for (int i = 0; i < numBlocks; i++) { if (i == (numBlocks - 1)) { b = new byte[(int) blocksize / 2]; } rand.nextBytes(b); stm.write(b); crc.update(b); } stm.close(); return crc.getValue(); }
32. TestRaidDfs#createTestFile()
Project: hadoop-20
File: TestRaidDfs.java
File: TestRaidDfs.java
// // creates a file and populate it with random data. Returns its crc. // public static long createTestFile(FileSystem fileSys, Path name, int repl, int numBlocks, long blocksize) throws IOException { CRC32 crc = new CRC32(); Random rand = new Random(); FSDataOutputStream stm = fileSys.create(name, true, fileSys.getConf().getInt("io.file.buffer.size", 4096), (short) repl, blocksize); // fill random data into file final byte[] b = new byte[(int) blocksize]; for (int i = 0; i < numBlocks; i++) { rand.nextBytes(b); stm.write(b); crc.update(b); } stm.close(); return crc.getValue(); }
33. T6836682#computeCRC()
Project: error-prone-javac
File: T6836682.java
File: T6836682.java
static long computeCRC(File inFile) throws IOException { byte[] buffer = new byte[8192]; CRC32 crc = new CRC32(); FileInputStream fis = null; BufferedInputStream bis = null; try { fis = new FileInputStream(inFile); bis = new BufferedInputStream(fis); int n = bis.read(buffer); while (n > 0) { crc.update(buffer, 0, n); n = bis.read(buffer); } } finally { Utils.close(bis); Utils.close(fis); } return crc.getValue(); }
34. DecoderUtil#isCRC32Valid()
Project: elasticsearch-knapsack
File: DecoderUtil.java
File: DecoderUtil.java
public static boolean isCRC32Valid(byte[] buf, int off, int len, int ref_off) { CRC32 crc32 = new CRC32(); crc32.update(buf, off, len); long value = crc32.getValue(); for (int i = 0; i < 4; ++i) { if ((byte) (value >>> (i * 8)) != buf[ref_off + i]) { return false; } } return true; }
35. BlobClob4BlobTest#getStreamCheckSum()
Project: derby
File: BlobClob4BlobTest.java
File: BlobClob4BlobTest.java
/** * Get the CRC32 checksum of a stream, reading * its contents entirely and closing it. */ private long getStreamCheckSum(InputStream in) throws Exception { CRC32 sum = new CRC32(); byte[] buf = new byte[32 * 1024]; for (; ; ) { int read = in.read(buf); if (read == -1) break; sum.update(buf, 0, read); } in.close(); return sum.getValue(); }
36. ChildAssocEntity#getChildNodeNameCrc()
Project: community-edition
File: ChildAssocEntity.java
File: ChildAssocEntity.java
/** * Find a CRC value for the association's child node name using UTF-8 conversion. * * @param childNodeName the child node name * @return Returns the CRC value (UTF-8 compatible) */ public static Long getChildNodeNameCrc(String childNodeName) { CRC32 crc = new CRC32(); try { // https://issues.alfresco.com/jira/browse/ALFCOM-1335 crc.update(childNodeName.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 encoding is not supported"); } return crc.getValue(); }
37. ChildAssocEntity#getQNameCrc()
Project: community-edition
File: ChildAssocEntity.java
File: ChildAssocEntity.java
/** * Find a CRC value for the full QName using UTF-8 conversion. * * @param qname the association qname * @return Returns the CRC value (UTF-8 compatible) */ public static Long getQNameCrc(QName qname) { CRC32 crc = new CRC32(); try { crc.update(qname.getNamespaceURI().getBytes("UTF-8")); crc.update(qname.getLocalName().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 encoding is not supported"); } return crc.getValue(); }
38. M2Model#getChecksum()
Project: community-edition
File: M2Model.java
File: M2Model.java
public long getChecksum(ModelDefinition.XMLBindingType bindingType) { final CRC32 crc = new CRC32(); // construct the crc directly from the model's xml stream toXML(bindingType, new OutputStream() { public void write(int b) throws IOException { crc.update(b); } }); return crc.getValue(); }
39. T6836682#computeCRC()
Project: ceylon-compiler
File: T6836682.java
File: T6836682.java
static long computeCRC(File inFile) throws IOException { byte[] buffer = new byte[8192]; CRC32 crc = new CRC32(); FileInputStream fis = null; BufferedInputStream bis = null; try { fis = new FileInputStream(inFile); bis = new BufferedInputStream(fis); int n = bis.read(buffer); while (n > 0) { crc.update(buffer, 0, n); n = bis.read(buffer); } } finally { Utils.close(bis); Utils.close(fis); } return crc.getValue(); }
40. T6836682#computeCRC()
Project: ceylon
File: T6836682.java
File: T6836682.java
static long computeCRC(File inFile) throws IOException { byte[] buffer = new byte[8192]; CRC32 crc = new CRC32(); FileInputStream fis = null; BufferedInputStream bis = null; try { fis = new FileInputStream(inFile); bis = new BufferedInputStream(fis); int n = bis.read(buffer); while (n > 0) { crc.update(buffer, 0, n); n = bis.read(buffer); } } finally { Utils.close(bis); Utils.close(fis); } return crc.getValue(); }
41. HintsDescriptor#serialize()
Project: cassandra
File: HintsDescriptor.java
File: HintsDescriptor.java
void serialize(DataOutputPlus out) throws IOException { CRC32 crc = new CRC32(); out.writeInt(version); updateChecksumInt(crc, version); out.writeLong(timestamp); updateChecksumLong(crc, timestamp); out.writeLong(hostId.getMostSignificantBits()); updateChecksumLong(crc, hostId.getMostSignificantBits()); out.writeLong(hostId.getLeastSignificantBits()); updateChecksumLong(crc, hostId.getLeastSignificantBits()); byte[] paramsBytes = JSONValue.toJSONString(parameters).getBytes(StandardCharsets.UTF_8); out.writeInt(paramsBytes.length); updateChecksumInt(crc, paramsBytes.length); out.writeInt((int) crc.getValue()); out.write(paramsBytes); crc.update(paramsBytes, 0, paramsBytes.length); out.writeInt((int) crc.getValue()); }
42. ZipCombiner#writeEntryFromBuffer()
Project: bazel
File: ZipCombiner.java
File: ZipCombiner.java
/** Writes an entry with the given name, date and external file attributes from the buffer. */ private void writeEntryFromBuffer(ZipFileEntry entry, byte[] uncompressed) throws IOException { CRC32 crc = new CRC32(); crc.update(uncompressed); entry.setCrc(crc.getValue()); entry.setSize(uncompressed.length); if (mode == OutputMode.FORCE_STORED) { entry.setMethod(Compression.STORED); entry.setCompressedSize(uncompressed.length); writeEntry(entry, new ByteArrayInputStream(uncompressed)); } else { ByteArrayOutputStream compressed = new ByteArrayOutputStream(); copyStream(new DeflaterInputStream(new ByteArrayInputStream(uncompressed), getDeflater()), compressed); entry.setMethod(Compression.DEFLATED); entry.setCompressedSize(compressed.size()); writeEntry(entry, new ByteArrayInputStream(compressed.toByteArray())); } }
43. ZipUtil#storeEntry()
Project: bazel
File: ZipUtil.java
File: ZipUtil.java
/** * This is a helper method for adding an uncompressed entry to a * ZipOutputStream. The entry timestamp is also set to a fixed value. * * @param name filename to use within the zip file * @param content file contents * @param zip the ZipOutputStream to which this entry will be appended */ public static void storeEntry(String name, byte[] content, ZipOutputStream zip) throws IOException { ZipEntry entry = new ZipEntry(name); entry.setMethod(ZipEntry.STORED); entry.setTime(DOS_EPOCH); entry.setSize(content.length); CRC32 crc32 = new CRC32(); crc32.update(content); entry.setCrc(crc32.getValue()); zip.putNextEntry(entry); zip.write(content); zip.closeEntry(); }
44. TextUtils#hashString()
Project: atlasdb
File: TextUtils.java
File: TextUtils.java
public static long hashString(final String externalKey) { if (null == externalKey) { return 0; } CRC32 crc = new CRC32(); try { crc.update(externalKey.getBytes(TextUtils.CHARSET_UTF_8)); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF-8 must be supported", e); } return crc.getValue(); }
45. SteamSharedLibraryLoader#crc()
Project: steamworks4j
File: SteamSharedLibraryLoader.java
File: SteamSharedLibraryLoader.java
private String crc(InputStream input) { CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(buffer, 0, length); } } catch (IOException e) { e.printStackTrace(); } finally { try { input.close(); } catch (IOException ignored) { } } return Long.toHexString(crc.getValue()); }
46. SharedLibraryExtractor#crc()
Project: playn
File: SharedLibraryExtractor.java
File: SharedLibraryExtractor.java
/** Returns a CRC of the remaining bytes in the stream. */ private String crc(InputStream input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(buffer, 0, length); } } catch (Exception ex) { try { input.close(); } catch (Exception ignored) { } } return Long.toString(crc.getValue()); }
47. SharedLibraryLoader#crc()
Project: libgdx
File: SharedLibraryLoader.java
File: SharedLibraryLoader.java
/** Returns a CRC of the remaining bytes in the stream. */ public String crc(InputStream input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(buffer, 0, length); } } catch (Exception ex) { StreamUtils.closeQuietly(input); } return Long.toString(crc.getValue(), 16); }
48. JniGenSharedLibraryLoader#crc()
Project: libgdx
File: JniGenSharedLibraryLoader.java
File: JniGenSharedLibraryLoader.java
/** Returns a CRC of the remaining bytes in the stream. */ public String crc(InputStream input) { // fallback if (input == null) return "" + System.nanoTime(); CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(buffer, 0, length); } } catch (Exception ex) { try { input.close(); } catch (Exception ignored) { } } return Long.toString(crc.getValue()); }
49. NativeSupport#CRC()
Project: LGame
File: NativeSupport.java
File: NativeSupport.java
public static String CRC(InputStream input) { if (input == null) { return "" + System.nanoTime(); } CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(buffer, 0, length); } } catch (Exception ex) { try { input.close(); } catch (Exception ignored) { } } return Long.toString(crc.getValue()); }
50. NativeSupport#CRC()
Project: LGame
File: NativeSupport.java
File: NativeSupport.java
public static String CRC(InputStream input) { if (input == null) { return "" + System.nanoTime(); } CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(buffer, 0, length); } } catch (Exception ex) { try { input.close(); } catch (Exception ignored) { } } return Long.toString(crc.getValue()); }
51. FileObject#crc32()
Project: jphp
File: FileObject.java
File: FileObject.java
@Signature public Memory crc32(Environment env, Memory... args) { CRC32 crcMaker = new CRC32(); byte[] buffer = new byte[1024]; int len; FileInputStream is; try { is = new FileInputStream(file); while ((len = is.read(buffer)) > 0) { crcMaker.update(buffer, 0, len); } is.close(); return LongMemory.valueOf(crcMaker.getValue()); } catch (FileNotFoundException e) { return Memory.NULL; } catch (IOException e) { return Memory.NULL; } }
52. TestRaidNode#validateFile()
Project: hadoop-20
File: TestRaidNode.java
File: TestRaidNode.java
// // validates that file matches the crc. // private void validateFile(FileSystem fileSys, Path name1, Path name2, long crc) throws IOException { FileStatus stat1 = fileSys.getFileStatus(name1); FileStatus stat2 = fileSys.getFileStatus(name2); assertTrue(" Length of file " + name1 + " is " + stat1.getLen() + " is different from length of file " + name1 + " " + stat2.getLen(), stat1.getLen() == stat2.getLen()); CRC32 newcrc = new CRC32(); FSDataInputStream stm = fileSys.open(name2); final byte[] b = new byte[4192]; int num = 0; while (num >= 0) { num = stm.read(b); if (num < 0) { break; } newcrc.update(b, 0, num); } stm.close(); if (newcrc.getValue() != crc) { fail("CRC mismatch of files " + name1 + " with file " + name2); } }
53. SqlMigrationResolver#calculateChecksum()
Project: flyway
File: SqlMigrationResolver.java
File: SqlMigrationResolver.java
/** * Calculates the checksum of this string. * * @param str The string to calculate the checksum for. * @return The crc-32 checksum of the bytes. */ /* private -> for testing */ static int calculateChecksum(Resource resource, String str) { final CRC32 crc32 = new CRC32(); BufferedReader bufferedReader = new BufferedReader(new StringReader(str)); try { String line; while ((line = bufferedReader.readLine()) != null) { crc32.update(line.getBytes("UTF-8")); } } catch (IOException e) { String message = "Unable to calculate checksum"; if (resource != null) { message += " for " + resource.getLocation() + " (" + resource.getLocationOnDisk() + ")"; } throw new FlywayException(message, e); } return (int) crc32.getValue(); }
54. ErlBif#crc32()
Project: erjang
File: ErlBif.java
File: ErlBif.java
@BIF static ENumber crc32(EObject num, EObject io_list) { EInteger init; long val; if (((init = num.testInteger()) == null) || (val = init.longValue()) != (val & 0xffffffffL)) { throw ERT.badarg(num, io_list); } CRC32 crc = new CRC32(); try { CRC32_crc.setInt(crc, (int) val); } catch (IllegalArgumentExceptionIllegalAccessException | e) { throw new RuntimeException(e); } EIOListVisitor.update(io_list, crc); return ERT.box(crc.getValue()); }
55. CompressedXContent#crc32()
Project: elasticsearch
File: CompressedXContent.java
File: CompressedXContent.java
private static int crc32(BytesReference data) { OutputStream dummy = new OutputStream() { @Override public void write(int b) throws IOException { // no-op } @Override public void write(byte[] b, int off, int len) throws IOException { // no-op } }; CRC32 crc32 = new CRC32(); try { data.writeTo(new CheckedOutputStream(dummy, crc32)); } catch (IOException bogus) { throw new Error(bogus); } return (int) crc32.getValue(); }
56. CompressedXContent#crc32()
Project: elassandra
File: CompressedXContent.java
File: CompressedXContent.java
private static int crc32(BytesReference data) { OutputStream dummy = new OutputStream() { @Override public void write(int b) throws IOException { // no-op } @Override public void write(byte[] b, int off, int len) throws IOException { // no-op } }; CRC32 crc32 = new CRC32(); try { data.writeTo(new CheckedOutputStream(dummy, crc32)); } catch (IOException bogus) { throw new Error(bogus); } return (int) crc32.getValue(); }
57. HintsWriteThenReadTest#calculateChecksum()
Project: cassandra
File: HintsWriteThenReadTest.java
File: HintsWriteThenReadTest.java
private static int calculateChecksum(File file) throws IOException { CRC32 crc = new CRC32(); byte[] buffer = new byte[FBUtilities.MAX_UNSIGNED_SHORT]; try (InputStream in = Files.newInputStream(file.toPath())) { int bytesRead; while ((bytesRead = in.read(buffer)) != -1) crc.update(buffer, 0, bytesRead); } return (int) crc.getValue(); }
58. CommitLogDescriptor#writeHeader()
Project: cassandra
File: CommitLogDescriptor.java
File: CommitLogDescriptor.java
/** * @param additionalHeaders Allow segments to pass custom header data */ public static void writeHeader(ByteBuffer out, CommitLogDescriptor descriptor, Map<String, String> additionalHeaders) { CRC32 crc = new CRC32(); out.putInt(descriptor.version); updateChecksumInt(crc, descriptor.version); out.putLong(descriptor.id); updateChecksumInt(crc, (int) (descriptor.id & 0xFFFFFFFFL)); updateChecksumInt(crc, (int) (descriptor.id >>> 32)); if (descriptor.version >= VERSION_22) { String parametersString = constructParametersString(descriptor.compression, descriptor.encryptionContext, additionalHeaders); byte[] parametersBytes = parametersString.getBytes(StandardCharsets.UTF_8); if (parametersBytes.length != (((short) parametersBytes.length) & 0xFFFF)) throw new ConfigurationException(String.format("Compression parameters too long, length %d cannot be above 65535.", parametersBytes.length)); out.putShort((short) parametersBytes.length); updateChecksumInt(crc, parametersBytes.length); out.put(parametersBytes); crc.update(parametersBytes, 0, parametersBytes.length); } else assert descriptor.compression == null; out.putInt((int) crc.getValue()); }
59. FileUtils#checksumCrc32()
Project: Cafe
File: FileUtils.java
File: FileUtils.java
/** * Computes the checksum of a file using the CRC32 checksum routine. The * value of the checksum is returned. * * @param file * the file to checksum, must not be null * @return the checksum value or an exception is thrown. */ public static long checksumCrc32(File file) throws FileNotFoundException, IOException { CRC32 checkSummer = new CRC32(); CheckedInputStream cis = null; try { cis = new CheckedInputStream(new FileInputStream(file), checkSummer); byte[] buf = new byte[128]; while (cis.read(buf) >= 0) { // Just read for checksum to get calculated. } return checkSummer.getValue(); } finally { if (cis != null) { try { cis.close(); } catch (IOException e) { } } } }
60. DirectoryInputStream#getCRC()
Project: bnd
File: DirectoryInputStream.java
File: DirectoryInputStream.java
private CRC32 getCRC(File file) throws IOException { CRC32 crc = new CRC32(); FileInputStream in = new FileInputStream(file); try { byte data[] = new byte[BUFFER_SIZE]; int size = in.read(data); while (size > 0) { crc.update(data, 0, size); size = in.read(data); } } finally { in.close(); } return crc; }
61. ZipWriterTest#setup()
Project: bazel
File: ZipWriterTest.java
File: ZipWriterTest.java
@Before public void setup() throws IOException { rand = new Random(); cal = Calendar.getInstance(); cal.clear(); // Zip files have 7-bit year resolution. cal.set(Calendar.YEAR, rand.nextInt(128) + 1980); cal.set(Calendar.MONTH, rand.nextInt(12)); cal.set(Calendar.DAY_OF_MONTH, rand.nextInt(29)); cal.set(Calendar.HOUR_OF_DAY, rand.nextInt(24)); cal.set(Calendar.MINUTE, rand.nextInt(60)); // Zip files have 2 second resolution. cal.set(Calendar.SECOND, rand.nextInt(30) * 2); crc = new CRC32(); deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true); test = tmp.newFile("test.zip"); }
62. CRC32Test#test_getValue()
Project: j2objc
File: CRC32Test.java
File: CRC32Test.java
/** * @tests java.util.zip.CRC32#getValue() */ public void test_getValue() { // test methods of java.util.zip.crc32.getValue() CRC32 crc = new CRC32(); assertEquals("getValue() should return a zero as a result of constructing a CRC32 instance", 0, crc.getValue()); crc.reset(); crc.update(Integer.MAX_VALUE); // System.out.print("value of crc " + crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 4278190080 assertEquals("update(max) failed to update the checksum to the correct value ", 4278190080L, crc.getValue()); crc.reset(); byte byteEmpty[] = new byte[10000]; crc.update(byteEmpty); // System.out.print("value of crc"+crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 1295764014 assertEquals("update(byte[]) failed to update the checksum to the correct value ", 1295764014L, crc.getValue()); crc.reset(); crc.update(1); // System.out.print("value of crc"+crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 2768625435 // assertEquals("update(int) failed to update the checksum to the correct // value ",2768625435L, crc.getValue()); crc.reset(); assertEquals("reset failed to reset the checksum value to zero", 0, crc.getValue()); }
63. CRC32Test#test_updateI()
Project: j2objc
File: CRC32Test.java
File: CRC32Test.java
/** * @tests java.util.zip.CRC32#update(int) */ public void test_updateI() { // test methods of java.util.zip.crc32.update(int) CRC32 crc = new CRC32(); crc.update(1); // System.out.print("value of crc"+crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 2768625435 assertEquals("update(1) failed to update the checksum to the correct value ", 2768625435L, crc.getValue()); crc.reset(); crc.update(Integer.MAX_VALUE); // System.out.print("value of crc " + crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 4278190080 assertEquals("update(max) failed to update the checksum to the correct value ", 4278190080L, crc.getValue()); crc.reset(); crc.update(Integer.MIN_VALUE); // System.out.print("value of crc " + crc.getValue()); // Ran JDK and discovered that the value of the CRC should be // 3523407757 assertEquals("update(min) failed to update the checksum to the correct value ", 3523407757L, crc.getValue()); }
64. SevenZOutputFile#finish()
Project: commons-compress
File: SevenZOutputFile.java
File: SevenZOutputFile.java
/** * Finishes the addition of entries to this archive, without closing it. * * @throws IOException if archive is already closed. */ public void finish() throws IOException { if (finished) { throw new IOException("This archive has already been finished"); } finished = true; final long headerPosition = file.getFilePointer(); final ByteArrayOutputStream headerBaos = new ByteArrayOutputStream(); final DataOutputStream header = new DataOutputStream(headerBaos); writeHeader(header); header.flush(); final byte[] headerBytes = headerBaos.toByteArray(); file.write(headerBytes); final CRC32 crc32 = new CRC32(); // signature header file.seek(0); file.write(SevenZFile.sevenZSignature); // version file.write(0); file.write(2); // start header final ByteArrayOutputStream startHeaderBaos = new ByteArrayOutputStream(); final DataOutputStream startHeaderStream = new DataOutputStream(startHeaderBaos); startHeaderStream.writeLong(Long.reverseBytes(headerPosition - SevenZFile.SIGNATURE_HEADER_SIZE)); startHeaderStream.writeLong(Long.reverseBytes(0xffffFFFFL & headerBytes.length)); crc32.reset(); crc32.update(headerBytes); startHeaderStream.writeInt(Integer.reverseBytes((int) crc32.getValue())); startHeaderStream.flush(); final byte[] startHeaderBytes = startHeaderBaos.toByteArray(); crc32.reset(); crc32.update(startHeaderBytes); file.writeInt(Integer.reverseBytes((int) crc32.getValue())); file.write(startHeaderBytes); }
65. Utilities#getCrc()
Project: igv
File: Utilities.java
File: Utilities.java
/** * @param buffer * @return * @throws java.io.IOException */ private static long getCrc(byte[] buffer) throws IOException { CRC32 crc = new CRC32(); crc.reset(); crc.update(buffer, 0, buffer.length); return crc.getValue(); }
66. IndexInfo#writeStatusToFile()
Project: community-edition
File: IndexInfo.java
File: IndexInfo.java
private void writeStatusToFile(FileChannel channel) throws IOException { long size = getBufferSize(); ByteBuffer buffer; if (useNIOMemoryMapping) { MappedByteBuffer mbb = channel.map(MapMode.READ_WRITE, 0, size); mbb.load(); buffer = mbb; } else { channel.truncate(size); buffer = ByteBuffer.wrap(new byte[(int) size]); } buffer.position(0); buffer.putLong(version); CRC32 crc32 = new CRC32(); crc32.update((int) (version >>> 32) & 0xFFFFFFFF); crc32.update((int) (version >>> 0) & 0xFFFFFFFF); buffer.putInt(indexEntries.size()); crc32.update(indexEntries.size()); for (IndexEntry entry : indexEntries.values()) { String entryType = entry.getType().toString(); writeString(buffer, crc32, entryType); writeString(buffer, crc32, entry.getName()); writeString(buffer, crc32, entry.getParentName()); String entryStatus = entry.getStatus().toString(); writeString(buffer, crc32, entryStatus); writeString(buffer, crc32, entry.getMergeId()); buffer.putLong(entry.getDocumentCount()); crc32.update((int) (entry.getDocumentCount() >>> 32) & 0xFFFFFFFF); crc32.update((int) (entry.getDocumentCount() >>> 0) & 0xFFFFFFFF); buffer.putLong(entry.getDeletions()); crc32.update((int) (entry.getDeletions() >>> 32) & 0xFFFFFFFF); crc32.update((int) (entry.getDeletions() >>> 0) & 0xFFFFFFFF); buffer.put(entry.isDeletOnlyNodes() ? (byte) 1 : (byte) 0); crc32.update(entry.isDeletOnlyNodes() ? new byte[] { (byte) 1 } : new byte[] { (byte) 0 }); } buffer.putLong(crc32.getValue()); if (useNIOMemoryMapping) { ((MappedByteBuffer) buffer).force(); } else { buffer.rewind(); channel.position(0); channel.write(buffer); } }
67. ZipBug9695860#getCRC()
Project: android-vts
File: ZipBug9695860.java
File: ZipBug9695860.java
private long getCRC(byte[] data) { CRC32 crc = new CRC32(); crc.reset(); crc.update(data); return crc.getValue(); }
68. TestCRC32#main()
Project: openjdk
File: TestCRC32.java
File: TestCRC32.java
public static void main(String[] args) { int offset = Integer.getInteger("offset", 0); int msgSize = Integer.getInteger("msgSize", 512); boolean multi = false; int iters = 20000; int warmupIters = 20000; if (args.length > 0) { if (args[0].equals("-m")) { multi = true; } else { iters = Integer.valueOf(args[0]); } if (args.length > 1) { warmupIters = Integer.valueOf(args[1]); } } if (multi) { test_multi(warmupIters); return; } System.out.println(" offset = " + offset); System.out.println("msgSize = " + msgSize + " bytes"); System.out.println(" iters = " + iters); byte[] b = initializedBytes(msgSize, offset); CRC32 crc0 = new CRC32(); CRC32 crc1 = new CRC32(); CRC32 crc2 = new CRC32(); crc0.update(b, offset, msgSize); System.out.println("-------------------------------------------------------"); /* warm up */ for (int i = 0; i < warmupIters; i++) { crc1.reset(); crc1.update(b, offset, msgSize); } /* measure performance */ long start = System.nanoTime(); for (int i = 0; i < iters; i++) { crc1.reset(); crc1.update(b, offset, msgSize); } long end = System.nanoTime(); // in seconds double total = (double) (end - start) / 1e9; // in MB/s double thruput = (double) msgSize * iters / 1e6 / total; System.out.println("CRC32.update(byte[]) runtime = " + total + " seconds"); System.out.println("CRC32.update(byte[]) throughput = " + thruput + " MB/s"); /* check correctness */ for (int i = 0; i < iters; i++) { crc1.reset(); crc1.update(b, offset, msgSize); if (!check(crc0, crc1)) break; } report("CRCs", crc0, crc1); System.out.println("-------------------------------------------------------"); ByteBuffer buf = ByteBuffer.allocateDirect(msgSize); buf.put(b, offset, msgSize); buf.flip(); /* warm up */ for (int i = 0; i < warmupIters; i++) { crc2.reset(); crc2.update(buf); buf.rewind(); } /* measure performance */ start = System.nanoTime(); for (int i = 0; i < iters; i++) { crc2.reset(); crc2.update(buf); buf.rewind(); } end = System.nanoTime(); // in seconds total = (double) (end - start) / 1e9; // in MB/s thruput = (double) msgSize * iters / 1e6 / total; System.out.println("CRC32.update(ByteBuffer) runtime = " + total + " seconds"); System.out.println("CRC32.update(ByteBuffer) throughput = " + thruput + " MB/s"); /* check correctness */ for (int i = 0; i < iters; i++) { crc2.reset(); crc2.update(buf); buf.rewind(); if (!check(crc0, crc2)) break; } report("CRCs", crc0, crc2); System.out.println("-------------------------------------------------------"); }
69. ComponentResource#getBodyChecksum()
Project: idecore
File: ComponentResource.java
File: ComponentResource.java
@Override public long getBodyChecksum() { final byte[] content = this.file; if (null == content) return INIT_CHECKSUM; CRC32 checksum = new CRC32(); checksum.update(content, 0, content.length); return checksum.getValue(); }
70. TestLookasideCache#bufferCRC()
Project: hadoop-20
File: TestLookasideCache.java
File: TestLookasideCache.java
/** * returns the CRC32 of the buffer */ private long bufferCRC(byte[] buf) { CRC32 crc = new CRC32(); crc.update(buf, 0, buf.length); return crc.getValue(); }
71. TestDecoder#verifyDecoder()
Project: hadoop-20
File: TestDecoder.java
File: TestDecoder.java
public void verifyDecoder(String code, int parallelism) throws Exception { Codec codec = Codec.getCodec(code); conf.setInt("raid.encoder.parallelism", parallelism); ConfigBuilder cb = new ConfigBuilder(CONFIG_FILE); cb.addPolicy("RaidTest1", "/user/dikang/raidtest/file" + code + parallelism, 1, 1, code); cb.persist(); Path srcPath = new Path("/user/dikang/raidtest/file" + code + parallelism + "/file1"); long blockSize = 8192 * 1024L; long crc = TestRaidDfs.createTestFilePartialLastBlock(fileSys, srcPath, 1, 7, blockSize); doRaid(srcPath, codec); FileStatus srcStat = fileSys.getFileStatus(srcPath); ParityFilePair pair = ParityFilePair.getParityFile(codec, srcStat, conf); FileStatus file1Stat = fileSys.getFileStatus(srcPath); long length = file1Stat.getLen(); LocatedBlocks file1Loc = RaidDFSUtil.getBlockLocations((DistributedFileSystem) fileSys, srcPath.toUri().getPath(), 0, length); // corrupt file int[] corruptBlockIdxs = new int[] { 5 }; long errorOffset = 5 * blockSize; for (int idx : corruptBlockIdxs) { TestBlockFixer.corruptBlock(file1Loc.get(idx).getBlock(), dfsCluster); } RaidDFSUtil.reportCorruptBlocks((DistributedFileSystem) fileSys, srcPath, corruptBlockIdxs, blockSize); Decoder decoder = new Decoder(conf, codec); ByteArrayOutputStream out = new ByteArrayOutputStream(); decoder.codec.simulateBlockFix = true; CRC32 oldCRC = decoder.fixErasedBlock(fileSys, srcStat, fileSys, pair.getPath(), true, blockSize, errorOffset, blockSize, false, out, null, null, false); decoder.codec.simulateBlockFix = false; out = new ByteArrayOutputStream(); decoder.fixErasedBlock(fileSys, srcStat, fileSys, pair.getPath(), true, blockSize, errorOffset, blockSize, false, out, null, null, false); // calculate the new crc CRC32 newCRC = new CRC32(); byte[] constructedBytes = out.toByteArray(); newCRC.update(constructedBytes); assertEquals(oldCRC.getValue(), newCRC.getValue()); }
72. TestRaidDfs#bufferCRC()
Project: hadoop-20
File: TestRaidDfs.java
File: TestRaidDfs.java
static long bufferCRC(byte[] buf) { CRC32 crc = new CRC32(); crc.update(buf, 0, buf.length); return crc.getValue(); }
73. GsCollectionsCodeGenerator#calculateChecksum()
Project: gs-collections
File: GsCollectionsCodeGenerator.java
File: GsCollectionsCodeGenerator.java
private static long calculateChecksum(String string) { CRC32 checksum = new CRC32(); checksum.update(string.getBytes(StandardCharsets.UTF_8)); return checksum.getValue(); }
74. AckChecksumChecker#append()
Project: flume
File: AckChecksumChecker.java
File: AckChecksumChecker.java
@Override public void append(Event e) throws IOException, InterruptedException { byte[] btyp = e.get(AckChecksumInjector.ATTR_ACK_TYPE); if (btyp == null) { // pass through if has no checksumming tags super.append(e); return; } byte[] btag = e.get(AckChecksumInjector.ATTR_ACK_TAG); byte[] bchk = e.get(AckChecksumInjector.ATTR_ACK_HASH); String k = new String(btag); if (Arrays.equals(btyp, AckChecksumInjector.CHECKSUM_START)) { LOG.info("Starting checksum group called " + k); // Checksum Start marker: create new partial long newchk = ByteBuffer.wrap(bchk).getLong(); LOG.info("initial checksum is " + Long.toHexString(newchk)); partial.put(k, newchk); ackStarts.incrementAndGet(); listener.start(k); return; } else if (Arrays.equals(btyp, AckChecksumInjector.CHECKSUM_STOP)) { LOG.info("Finishing checksum group called '" + k + "'"); ackEnds.incrementAndGet(); // Checksum stop marker: move from partial to done Long chksum = partial.get(k); if (chksum == null) { LOG.error("checksum failed"); listener.err(k); ackFails.incrementAndGet(); return; } long endchk = ByteBuffer.wrap(bchk).getLong(); LOG.debug("final checksum is " + Long.toHexString(endchk) + " stop checksum is " + Long.toHexString(chksum)); if ((chksum ^ endchk) != 0) { // There was a problem. LOG.warn("[ Thread " + Thread.currentThread().getId() + " ] Some component of msg group was lost or duped " + k); listener.err(k); ackFails.incrementAndGet(); return; } LOG.info("Checksum succeeded " + Long.toHexString(chksum)); listener.end(k); ackSuccesses.incrementAndGet(); partial.remove(k); LOG.info("moved from partial to complete " + k); return; } // normal case, just an update the checksum. CRC32 chk = new CRC32(); chk.reset(); chk.update(e.getBody()); long chkVal = chk.getValue(); if (chkVal != ByteBuffer.wrap(bchk).getLong()) { LOG.warn("check sum does not match!"); } super.append(e); // only do this after we have successfully sent the event. synchronized (partial) { Long chks = partial.get(k); if (chks == null) { // throw new IOException("Ack tag '" + k + "' was not started: "); unstarted++; return; } // update checksum. long checksum = partial.get(k); checksum ^= chkVal; partial.put(k, checksum); } }
75. SupportHashCodeFuncGranularCRC32#computeCRC32()
Project: esper
File: SupportHashCodeFuncGranularCRC32.java
File: SupportHashCodeFuncGranularCRC32.java
public static long computeCRC32(String key) { CRC32 crc = new CRC32(); crc.update(key.getBytes()); return crc.getValue(); }
76. EBinary#crc()
Project: erjang
File: EBinary.java
File: EBinary.java
public long crc() { CRC32 crc = new CRC32(); int octets = byteSize(); crc.update(data, byteOffset(), octets); return crc.getValue(); }
77. EclipseCollectionsCodeGenerator#calculateChecksum()
Project: eclipse-collections
File: EclipseCollectionsCodeGenerator.java
File: EclipseCollectionsCodeGenerator.java
private static long calculateChecksum(String string) { CRC32 checksum = new CRC32(); checksum.update(string.getBytes(StandardCharsets.UTF_8)); return checksum.getValue(); }
78. TestHashFunctions#testHashPerf()
Project: databus
File: TestHashFunctions.java
File: TestHashFunctions.java
public void testHashPerf(int capacity) { byte[] b = new byte[capacity]; ByteBuffer buf = ByteBuffer.allocateDirect(capacity).order(_eventFactory.getByteOrder()); Random r = new Random(); r.nextBytes(b); buf.put(b); FnvHashFunction fun = new FnvHashFunction(); CRC32 chksum = new CRC32(); JenkinsHashFunction jFun = new JenkinsHashFunction(); long start = 0; long end = 0; long hash = 0; long diff = 0; long delayMicro = 0; chksum.reset(); chksum.update(b); long prevhash = chksum.getValue(); for (int i = 0; i < 10; i++) { start = System.nanoTime(); chksum.reset(); chksum.update(b); hash = chksum.getValue(); end = System.nanoTime(); assert (prevhash == hash); diff += (end - start); } delayMicro = (diff / 1000) / 10; System.out.println("Latency (microseconds) of system CRC32 for byte[] is: " + delayMicro); prevhash = fun.hash(b); for (int i = 0; i < 10; i++) { start = System.nanoTime(); hash = fun.hash(b); end = System.nanoTime(); assert (prevhash == hash); diff += (end - start); } delayMicro = (diff / 1000) / 10; System.out.println("Latency (microseconds) of FNV for byte[] is: " + delayMicro); prevhash = jFun.hash(b); for (int i = 0; i < 10; i++) { start = System.nanoTime(); hash = jFun.hash(b); end = System.nanoTime(); assert (prevhash == hash); diff += (end - start); } delayMicro = (diff / 1000) / 10; System.out.println("Latency (microseconds) of Jenkins for byte[] is: " + delayMicro); prevhash = ByteBufferCRC32.getChecksum(b); for (int i = 0; i < 10; i++) { start = System.nanoTime(); hash = ByteBufferCRC32.getChecksum(b); end = System.nanoTime(); assert (prevhash == hash); diff += (end - start); } delayMicro = (diff / 1000) / 10; System.out.println("Latency (microseconds) of ByteBufferCRC32 for byte[] is: " + delayMicro); //System.out.println("Buffer position-Remaining :" + buf.position() + "-" + buf.remaining()); prevhash = fun.hash(buf); for (int i = 0; i < 10; i++) { start = System.nanoTime(); hash = fun.hash(buf); end = System.nanoTime(); assert (prevhash == hash); diff += (end - start); } delayMicro = (diff / 1000) / 10; System.out.println("Latency (microseconds) of FNV for ByteBuffer is: " + delayMicro); //System.out.println("Buffer position-Remaining :" + buf.position() + "-" + buf.remaining()); prevhash = fun.hash(buf); for (int i = 0; i < 10; i++) { start = System.nanoTime(); hash = fun.hash(buf); end = System.nanoTime(); assert (prevhash == hash); diff += (end - start); } delayMicro = (diff / 1000) / 10; System.out.println("Latency (microseconds) of Jenkins for ByteBuffer is: " + delayMicro); //System.out.println("Buffer position-Remaining :" + buf.position() + "-" + buf.remaining()); prevhash = ByteBufferCRC32.getChecksum(buf); for (int i = 0; i < 10; i++) { start = System.nanoTime(); hash = ByteBufferCRC32.getChecksum(buf); end = System.nanoTime(); assert (prevhash == hash); diff += (end - start); } delayMicro = (diff / 1000) / 10; System.out.println("Latency (microseconds) of ByteBufferCRC32 for ByteBuffer is: " + delayMicro); //System.out.println("Buffer position-Remaining :" + buf.position() + "-" + buf.remaining()); }
79. TextUtils#checksum()
Project: cgeo
File: TextUtils.java
File: TextUtils.java
/** * Calculate a simple checksum for change-checking (not usable for security/cryptography!) * * @param input * String to check * @return resulting checksum */ public static long checksum(final String input) { final CRC32 checksum = new CRC32(); checksum.update(input.getBytes(CHARSET_UTF8)); return checksum.getValue(); }
80. LogRecord#computeChecksum()
Project: cassandra
File: LogRecord.java
File: LogRecord.java
long computeChecksum() { CRC32 crc32 = new CRC32(); crc32.update((absolutePath()).getBytes(FileUtils.CHARSET)); crc32.update(type.toString().getBytes(FileUtils.CHARSET)); FBUtilities.updateChecksumInt(crc32, (int) updateTime); FBUtilities.updateChecksumInt(crc32, (int) (updateTime >>> 32)); FBUtilities.updateChecksumInt(crc32, numFiles); return crc32.getValue() & (Long.MAX_VALUE); }
81. ZipReaderTest#testZip64()
Project: bazel
File: ZipReaderTest.java
File: ZipReaderTest.java
@Test public void testZip64() throws IOException { // Generated with: 'echo "foo" > entry; zip -fz -q out.zip entry' byte[] data = new byte[] { 0x50, 0x4b, 0x03, 0x04, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d, (byte) 0x86, (byte) 0xa6, 0x46, (byte) 0xa8, 0x65, 0x32, 0x7e, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x05, 0x00, 0x30, 0x00, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x55, 0x54, 0x09, 0x00, 0x03, (byte) 0xb2, 0x7e, 0x4a, 0x55, (byte) 0xb2, 0x7e, 0x4a, 0x55, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04, 0x46, 0x3a, 0x04, 0x00, 0x04, (byte) 0x88, 0x13, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x6f, 0x0a, 0x50, 0x4b, 0x01, 0x02, 0x1e, 0x03, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d, (byte) 0x86, (byte) 0xa6, 0x46, (byte) 0xa8, 0x65, 0x32, 0x7e, 0x04, 0x00, 0x00, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x05, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, (byte) 0xa0, (byte) 0x81, 0x00, 0x00, 0x00, 0x00, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x55, 0x54, 0x05, 0x00, 0x03, (byte) 0xb2, 0x7e, 0x4a, 0x55, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04, 0x46, 0x3a, 0x04, 0x00, 0x04, (byte) 0x88, 0x13, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x06, 0x06, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x03, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, (byte) 0xae, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x57, 0x00, 0x00, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x00 }; try (FileOutputStream out = new FileOutputStream(test)) { out.write(data); } String foo = "foo\n"; byte[] expectedFooData = foo.getBytes(UTF_8); ExtraDataList extras = new ExtraDataList(); extras.add(new ExtraData((short) 0x0001, ZipUtil.longToLittleEndian(expectedFooData.length))); byte[] extra = extras.getBytes(); CRC32 crc = new CRC32(); crc.reset(); crc.update(expectedFooData); try (ZipReader reader = new ZipReader(test, UTF_8)) { ZipFileEntry fooEntry = reader.getEntry("entry"); InputStream fooIn = reader.getInputStream(fooEntry); byte[] fooData = new byte[expectedFooData.length]; fooIn.read(fooData); assertThat(fooData).isEqualTo(expectedFooData); assertThat(fooEntry.getName()).isEqualTo("entry"); assertThat(fooEntry.getComment()).isEqualTo(""); assertThat(fooEntry.getMethod()).isEqualTo(Compression.STORED); assertThat(fooEntry.getVersionNeeded()).isEqualTo(Feature.ZIP64_SIZE.getMinVersion()); assertThat(fooEntry.getSize()).isEqualTo(expectedFooData.length); assertThat(fooEntry.getCompressedSize()).isEqualTo(expectedFooData.length); assertThat(fooEntry.getCrc()).isEqualTo(crc.getValue()); assertThat(fooEntry.getExtra().get((short) 0x0001).getBytes()).isEqualTo(extra); } }
82. ZipFactory#calculateCrc32()
Project: bazel
File: ZipFactory.java
File: ZipFactory.java
public static long calculateCrc32(byte[] content) { CRC32 crc = new CRC32(); crc.update(content); return crc.getValue(); }
83. MessageSetBuilder#getCRC()
Project: suro
File: MessageSetBuilder.java
File: MessageSetBuilder.java
/** * Compute CRC32 value for byte[] * * @param buffer all the bytes in the buffer will be used for CRC32 calculation * * @return a CRC32 value for the given byte array */ public static long getCRC(byte[] buffer) { CRC32 crc = new CRC32(); crc.update(buffer); return crc.getValue(); }
84. Digests#crc32AsLong()
Project: springside4
File: Digests.java
File: Digests.java
/** * ????????crc32????php????64bit???????????long */ public static long crc32AsLong(String input, Charset charset) { CRC32 crc32 = new CRC32(); crc32.update(input.getBytes(charset)); return crc32.getValue(); }
85. Digests#crc32AsLong()
Project: springside4
File: Digests.java
File: Digests.java
/** * ????????crc32????php????64bit???????????long */ public static long crc32AsLong(String input) { CRC32 crc32 = new CRC32(); crc32.update(input.getBytes(Charsets.UTF8)); return crc32.getValue(); }
86. Digests#crc32AsLong()
Project: springside4
File: Digests.java
File: Digests.java
/** * ????????crc32????php????64bit???????????long */ public static long crc32AsLong(byte[] input) { CRC32 crc32 = new CRC32(); crc32.update(input); return crc32.getValue(); }
87. RootbeerCompiler#calcCrc32()
Project: rootbeer1
File: RootbeerCompiler.java
File: RootbeerCompiler.java
private long calcCrc32(byte[] buffer) { CRC32 crc = new CRC32(); crc.update(buffer); return crc.getValue(); }
88. InstructionGroupCreatorTest#computeCRC()
Project: parboiled
File: InstructionGroupCreatorTest.java
File: InstructionGroupCreatorTest.java
private static long computeCRC(String text) throws Exception { CRC32 crc32 = new CRC32(); byte[] buf = text.getBytes("UTF8"); crc32.update(buf); return crc32.getValue(); }
89. Utils#crc32()
Project: jafka
File: Utils.java
File: Utils.java
/** * Compute the CRC32 of the segment of the byte array given by the * specificed size and offset * * @param bytes The bytes to checksum * @param offset the offset at which to begin checksumming * @param size the number of bytes to checksum * @return The CRC32 */ public static long crc32(byte[] bytes, int offset, int size) { CRC32 crc = new CRC32(); crc.update(bytes, offset, size); return crc.getValue(); }
90. NrpePacket#decode()
Project: zorka
File: NrpePacket.java
File: NrpePacket.java
/** * Reads data from input stream and populates fields with parsed values * * @param is input stream * * @throws IOException if I/O error occurs */ public void decode(InputStream is) throws IOException { byte[] buf = new byte[1036]; int len = is.read(buf); // Extract packet header ByteBuffer bb = ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN); version = bb.getShort(); type = bb.getShort(); byte[] crcBuf = new byte[8]; bb.get(crcBuf, 4, 4); long origCrc = ByteBuffer.wrap(crcBuf).order(ByteOrder.BIG_ENDIAN).getLong(); resultCode = bb.getShort(); System.arraycopy(crcBuf, 0, buf, 4, 4); CRC32 crc = new CRC32(); crc.update(buf, 0, len); if (crc.getValue() != origCrc) { throw new IOException("CRC error in received NRPE packet (packet content=" + ZorkaUtil.hex(buf, len) + ")"); } int msglen = 0; for (int i = 10; i < 1036; i++) { if (buf[i] == 0) { msglen = i - 10; break; } } byte[] msg = new byte[msglen]; bb.get(msg); data = new String(msg, "UTF-8"); }
91. ZicoConnector#recv()
Project: zorka
File: ZicoConnector.java
File: ZicoConnector.java
// TODO implement recv with timeout /** * Receives ZICO packet. * * @return unpacked object or status/error. * @throws IOException when communication error occurs. */ protected ZicoPacket recv() throws IOException { for (int sbyte : ZICO_MAGIC) { int b; if ((b = in.read()) != sbyte) { if (b != -1) { throw new ZicoException(ZicoPacket.ZICO_BAD_REPLY, "Malformed input data: invalid ZICO magic."); } else { throw new ZicoException(ZicoPacket.ZICO_EOD, "Peer disconnected. Try again."); } } } byte[] b = new byte[HEADER_LENGTH]; in.read(b); ByteBuffer buf = ByteBuffer.wrap(b); short type = buf.getShort(); int length = buf.getInt(); long crc32 = buf.getLong(); byte[] d = new byte[length]; int offs = 0; while (offs < length) { int rlen = in.read(d, offs, length - offs); if (rlen >= 0) { offs += rlen; } else { throw new ZicoException(ZicoPacket.ZICO_BAD_REQUEST, "Unexpected end of stream."); } } CRC32 crc = new CRC32(); crc.update(d); if (crc32 != crc.getValue()) { throw new ZicoException(ZicoPacket.ZICO_CRC_ERROR, "CRC error occured."); } return new ZicoPacket(type, d); }
92. ZorkaUtil#crc32()
Project: zorka
File: ZorkaUtil.java
File: ZorkaUtil.java
public static String crc32(String input) { CRC32 crc32 = new CRC32(); crc32.update(input.getBytes()); return String.format("%08x", crc32.getValue()); }
93. Digests#crc32()
Project: springside4
File: Digests.java
File: Digests.java
/** * ????????crc32??. */ public static int crc32(String input, Charset charset) { CRC32 crc32 = new CRC32(); crc32.update(input.getBytes(charset)); return (int) crc32.getValue(); }
94. Digests#crc32()
Project: springside4
File: Digests.java
File: Digests.java
/** * ????????crc32??. */ public static int crc32(String input) { CRC32 crc32 = new CRC32(); crc32.update(input.getBytes(Charsets.UTF8)); return (int) crc32.getValue(); }
95. Digests#crc32()
Project: springside4
File: Digests.java
File: Digests.java
/** * ????????crc32??. */ public static int crc32(byte[] input) { CRC32 crc32 = new CRC32(); crc32.update(input); return (int) crc32.getValue(); }
96. SerializeB#dumpinfo()
Project: spring-loaded
File: SerializeB.java
File: SerializeB.java
private void dumpinfo(byte[] bytes) { CRC32 crc = new CRC32(); crc.update(bytes, 0, bytes.length); System.out.println("byteinfo:len=" + bytes.length + ":crc=" + Long.toHexString(crc.getValue())); }
97. TagHelper#generateUniqueName()
Project: spacewalk
File: TagHelper.java
File: TagHelper.java
/** * Generates the unique name for a list * @param name list name * @return "uniquified" name */ public static String generateUniqueName(String name) { CRC32 crc = new CRC32(); crc.update(name.getBytes()); return String.valueOf(crc.getValue()); }
98. ObjectVersionListing#etag()
Project: s3auth
File: ObjectVersionListing.java
File: ObjectVersionListing.java
@Override public String etag() { final CRC32 crc = new CRC32(); crc.update(this.content); return Long.toHexString(crc.getValue()); }
99. DirectoryListing#etag()
Project: s3auth
File: DirectoryListing.java
File: DirectoryListing.java
@Override public String etag() { final CRC32 crc = new CRC32(); crc.update(this.content); return Long.toHexString(crc.getValue()); }
100. UtilAll#crc32()
Project: rocketmq-all
File: UtilAll.java
File: UtilAll.java
public static final int crc32(byte[] array, int offset, int length) { CRC32 crc32 = new CRC32(); crc32.update(array, offset, length); return (int) (crc32.getValue() & 0x7FFFFFFF); }