java.util.zip.CRC32.reset()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中java.util.zip.CRC32.reset()方法的一些代码示例,展示了CRC32.reset()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CRC32.reset()方法的具体详情如下:
包路径:java.util.zip.CRC32
类名称:CRC32
方法名:reset

CRC32.reset介绍

[英]Resets the CRC32 checksum to it initial state.
[中]将CRC32校验和重置为初始状态。

代码示例

代码示例来源: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: weibocom/motan

public static long getCrc32(byte[] b) {
  CRC32 crc = crc32Provider.get();
  crc.reset();
  crc.update(b);
  return crc.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: 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: 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: alipay/sofa-bolt

/**
 * Compute CRC32 code for byte[].
 *
 * @param array
 * @param offset
 * @param length
 * @return
 */
public static final int crc32(byte[] array, int offset, int length) {
  CRC32 crc32 = CRC_32_THREAD_LOCAL.get();
  crc32.update(array, offset, length);
  int ret = (int) crc32.getValue();
  crc32.reset();
  return ret;
}

代码示例来源:origin: apache/hive

/**
 * CRC32 for string
 */
public LongWritable evaluate(Text n) {
 if (n == null) {
  return null;
 }
 crc32.reset();
 crc32.update(n.getBytes(), 0, n.getLength());
 result.set(crc32.getValue());
 return result;
}

代码示例来源: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: twitter/distributedlog

/**
 * Generate crc32 for TruncateOp.
 */
public static Long truncateOpCRC32(String stream, DLSN dlsn) {
  CRC32 crc = requestCRC.get();
  try {
    crc.update(stream.getBytes(UTF_8));
    crc.update(dlsn.serializeBytes());
    return crc.getValue();
  } finally {
    crc.reset();
  }
}

代码示例来源:origin: apache/drill

/**
 * CRC32 for string
 */
public LongWritable evaluate(Text n) {
 if (n == null) {
  return null;
 }
 crc32.reset();
 crc32.update(n.getBytes(), 0, n.getLength());
 result.set(crc32.getValue());
 return result;
}

代码示例来源:origin: apache/avro

@Override public ByteBuffer compute(ByteBuffer data) {
 crc32.reset();
 crc32.update(data.array(), data.position(), data.remaining());
 ByteBuffer result = ByteBuffer.allocate(size());
 result.putInt((int)crc32.getValue());
 result.flip();
 return result;
}

代码示例来源:origin: org.apache.avro/avro

@Override
public ByteBuffer compress(ByteBuffer in) throws IOException {
 ByteBuffer out =
  ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4);
 int size = Snappy.compress(in.array(), in.position(), in.remaining(),
               out.array(), 0);
 crc32.reset();
 crc32.update(in.array(), in.position(), in.remaining());
 out.putInt(size, (int)crc32.getValue());
 out.limit(size+4);
 return out;
}

代码示例来源:origin: org.apache.avro/avro

@Override
public ByteBuffer decompress(ByteBuffer in) throws IOException {
 ByteBuffer out = ByteBuffer.allocate
  (Snappy.uncompressedLength(in.array(),in.position(),in.remaining()-4));
 int size = Snappy.uncompress(in.array(),in.position(),in.remaining()-4,
                out.array(), 0);
 out.limit(size);
 crc32.reset();
 crc32.update(out.array(), 0, size);
 if (in.getInt(in.limit()-4) != (int)crc32.getValue())
  throw new IOException("Checksum failure");
 return out;
}

代码示例来源:origin: apache/hive

/**
  * CRC32 for binary
  */
 public LongWritable evaluate(BytesWritable b) {
  if (b == null) {
   return null;
  }

  crc32.reset();
  crc32.update(b.getBytes(), 0, b.getLength());

  result.set(crc32.getValue());
  return result;
 }
}

代码示例来源:origin: apache/avro

@Override
public ByteBuffer compress(ByteBuffer in) throws IOException {
 int offset = computeOffset(in);
 ByteBuffer out =
  ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4);
 int size = Snappy.compress(in.array(), offset, in.remaining(),
               out.array(), 0);
 crc32.reset();
 crc32.update(in.array(), offset, in.remaining());
 out.putInt(size, (int)crc32.getValue());
 out.limit(size+4);
 return out;
}

代码示例来源:origin: apache/avro

@Override
public ByteBuffer decompress(ByteBuffer in) throws IOException {
 int offset = computeOffset(in);
 ByteBuffer out = ByteBuffer.allocate
  (Snappy.uncompressedLength(in.array(), offset, in.remaining()-4));
 int size = Snappy.uncompress(in.array(), offset, in.remaining()-4,
                out.array(), 0);
 out.limit(size);
 crc32.reset();
 crc32.update(out.array(), 0, size);
 if (in.getInt(in.limit()-4) != (int)crc32.getValue())
  throw new IOException("Checksum failure");
 return out;
}

代码示例来源:origin: apache/drill

/**
  * CRC32 for binary
  */
 public LongWritable evaluate(BytesWritable b) {
  if (b == null) {
   return null;
  }

  crc32.reset();
  crc32.update(b.getBytes(), 0, b.getLength());

  result.set(crc32.getValue());
  return result;
 }
}

代码示例来源:origin: alibaba/mdrill

/**
 * Write a PNG "IEND" chunk into the pngBytes array.
 */
protected void writeEnd() {
  this.bytePos = writeInt4(0, this.bytePos);
  this.bytePos = writeBytes(IEND, this.bytePos);
  this.crc.reset();
  this.crc.update(IEND);
  this.crcValue = this.crc.getValue();
  this.bytePos = writeInt4((int) this.crcValue, this.bytePos);
}

代码示例来源:origin: guoguibing/librec

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) {

相关文章

微信公众号

最新文章

更多