本文整理了Java中java.util.zip.CRC32.getValue()
方法的一些代码示例,展示了CRC32.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CRC32.getValue()
方法的具体详情如下:
包路径:java.util.zip.CRC32
类名称:CRC32
方法名:getValue
[英]Returns the CRC32 checksum for all input received.
[中]返回接收到的所有输入的CRC32校验和。
代码示例来源:origin: apache/rocketmq
public static int crc32(byte[] array, int offset, int length) {
CRC32 crc32 = new CRC32();
crc32.update(array, offset, length);
return (int) (crc32.getValue() & 0x7FFFFFFF);
}
代码示例来源:origin: dropwizard/dropwizard
private static String hash(byte[] resource) {
CRC_32.reset();
CRC_32.update(resource);
return Long.toHexString(CRC_32.getValue());
}
代码示例来源:origin: libgdx/libgdx
public void endChunk (DataOutputStream target) throws IOException {
flush();
target.writeInt(buffer.size() - 4);
buffer.writeTo(target);
target.writeInt((int)crc.getValue());
buffer.reset();
crc.reset();
}
}
代码示例来源:origin: guoguibing/librec
int bytesRead;
byte[] buffer = new byte[1024];
CRC32 crc = new CRC32();
for (File file : listFiles(dirPath)) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
crc.reset();
while ((bytesRead = bis.read(buffer)) != -1) {
crc.update(buffer, 0, bytesRead);
entry.setCompressedSize(file.length());
entry.setSize(file.length());
entry.setCrc(crc.getValue());
zos.putNextEntry(entry);
while ((bytesRead = bis.read(buffer)) != -1) {
代码示例来源:origin: commons-io/commons-io
/**
* 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 {@code null}
* @return the checksum value
* @throws NullPointerException if the file or checksum is {@code null}
* @throws IllegalArgumentException if the file is a directory
* @throws IOException if an IO error occurs reading the file
* @since 1.3
*/
public static long checksumCRC32(final File file) throws IOException {
final CRC32 crc = new CRC32();
checksum(file, crc);
return crc.getValue();
}
代码示例来源:origin: apache/ignite
/**
* @param crcAlgo CRC algorithm.
* @param buf Input buffer.
* @param len Buffer length.
*
* @return Crc checksum.
*/
private static int calcCrc(CRC32 crcAlgo, ByteBuffer buf, int len) {
int initLimit = buf.limit();
buf.limit(buf.position() + len);
crcAlgo.update(buf);
buf.limit(initLimit);
return (int)crcAlgo.getValue() ^ 0xFFFFFFFF;
}
}
代码示例来源:origin: libgdx/libgdx
/** Returns a CRC of the remaining bytes in the stream. */
public String crc (InputStream input) {
if (input == null) return "" + System.nanoTime(); // fallback
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());
}
代码示例来源:origin: weibocom/motan
public static long getCrc32(byte[] b) {
CRC32 crc = crc32Provider.get();
crc.reset();
crc.update(b);
return crc.getValue();
}
代码示例来源:origin: org.apache.commons/commons-compress
channel.write(ByteBuffer.wrap(headerBytes));
final CRC32 crc32 = new CRC32();
crc32.update(headerBytes);
.putInt((int) crc32.getValue());
crc32.reset();
crc32.update(bb.array(), SevenZFile.sevenZSignature.length + 6, 20);
bb.putInt(SevenZFile.sevenZSignature.length + 2, (int) crc32.getValue());
bb.flip();
channel.write(bb);
代码示例来源:origin: libgdx/libgdx
public void endChunk (DataOutputStream target) throws IOException {
flush();
target.writeInt(buffer.size() - 4);
buffer.writeTo(target);
target.writeInt((int)crc.getValue());
buffer.reset();
crc.reset();
}
}
代码示例来源:origin: org.apache.commons/commons-io
/**
* 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 <code>null</code>
* @return the checksum value
* @throws NullPointerException if the file or checksum is <code>null</code>
* @throws IllegalArgumentException if the file is a directory
* @throws IOException if an IO error occurs reading the file
* @since Commons IO 1.3
*/
public static long checksumCRC32(File file) throws IOException {
CRC32 crc = new CRC32();
checksum(file, crc);
return crc.getValue();
}
代码示例来源:origin: libgdx/libgdx
/** Returns a CRC of the remaining bytes in the stream. */
public String crc (InputStream input) {
if (input == null) return "" + System.nanoTime(); // fallback
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());
}
代码示例来源:origin: twitter/distributedlog
/**
* Generate crc32 for any op which only passes a stream name.
*/
public static Long streamOpCRC32(String stream) {
CRC32 crc = requestCRC.get();
try {
crc.update(stream.getBytes(UTF_8));
return crc.getValue();
} finally {
crc.reset();
}
}
}
代码示例来源:origin: loklak/loklak_server
bytePos = writeInt4(pngBytes, height, bytePos);
bytePos = writeBytes(pngBytes, new byte[]{8, 2, 0, 0, 0}, bytePos);
final CRC32 crc = new CRC32();
crc.reset();
crc.update(pngBytes, startPos, bytePos - startPos);
bytePos = writeInt4(pngBytes, (int) crc.getValue(), bytePos);
crc.reset();
bytePos = writeInt4(pngBytes, nCompressed, bytePos);
bytePos = writeBytes(pngBytes, IDAT, bytePos);
crc.update(IDAT);
System.arraycopy(outBytes.toByteArray(), 0, pngBytes, bytePos, outBytes.size());
outBytes.close();
outBytes = null;
crc.update(pngBytes, bytePos, nCompressed);
bytePos += nCompressed;
bytePos = writeInt4(pngBytes, (int) crc.getValue(), bytePos);
bytePos = writeInt4(pngBytes, 0, bytePos);
bytePos = writeBytes(pngBytes, IEND, bytePos);
crc.reset();
crc.update(IEND);
bytePos = writeInt4(pngBytes, (int) crc.getValue(), bytePos);
return pngBytes;
代码示例来源:origin: voldemort/voldemort
@Override
public byte[] getCheckSum() {
byte[] returnedCheckSum = new byte[ByteUtils.SIZE_OF_LONG];
ByteUtils.writeLong(returnedCheckSum, checkSumGenerator.getValue(), 0);
checkSumGenerator.reset();
return returnedCheckSum;
}
代码示例来源:origin: Tencent/tinker
public static long getFileCrc32(File file) throws IOException {
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(file));
CRC32 crc = new CRC32();
int cnt;
while ((cnt = inputStream.read()) != -1) {
crc.update(cnt);
}
return crc.getValue();
} finally {
StreamUtil.closeQuietly(inputStream);
}
}
代码示例来源:origin: twitter/distributedlog
/**
* Generate crc32 for WriteOp.
*/
public static Long writeOpCRC32(String stream, byte[] payload) {
CRC32 crc = requestCRC.get();
try {
crc.update(stream.getBytes(UTF_8));
crc.update(payload);
return crc.getValue();
} finally {
crc.reset();
}
}
代码示例来源:origin: igvteam/igv
/**
* @param buffer
* @return
* @throws java.io.IOException
*/
static private long getCrc(byte[] buffer) throws IOException {
CRC32 crc = new CRC32();
crc.reset();
crc.update(buffer, 0, buffer.length);
return crc.getValue();
}
代码示例来源:origin: org.apache.ant/ant
/**
* Writes all necessary data for this entry.
*
* @since 1.1
* @throws IOException on error
* @throws Zip64RequiredException if the entry's uncompressed or
* compressed size exceeds 4 GByte and {@link #setUseZip64}
* is {@link Zip64Mode#Never}.
*/
public void closeEntry() throws IOException {
preClose();
flushDeflater();
final Zip64Mode effectiveMode = getEffectiveZip64Mode(entry.entry);
long bytesWritten = written - entry.dataStart;
long realCrc = crc.getValue();
crc.reset();
final boolean actuallyNeedsZip64 =
handleSizesAndCrc(bytesWritten, realCrc, effectiveMode);
closeEntry(actuallyNeedsZip64);
}
代码示例来源:origin: killme2008/Metamorphosis
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);
}
}
内容来源于网络,如有侵权,请联系作者删除!