Tabnine Logo
Checksum.getValue
Code IndexAdd Tabnine to your IDE (free)

How to use
getValue
method
in
java.util.zip.Checksum

Best Java code snippets using java.util.zip.Checksum.getValue (Showing top 20 results out of 2,205)

Refine searchRefine arrow

  • Checksum.update
origin: apache/kafka

/**
 * Compute the CRC32C (Castagnoli) of the segment of the byte array given by the specified size and offset
 *
 * @param bytes The bytes to checksum
 * @param offset the offset at which to begin the checksum computation
 * @param size the number of bytes to checksum
 * @return The CRC32C
 */
public static long compute(byte[] bytes, int offset, int size) {
  Checksum crc = create();
  crc.update(bytes, offset, size);
  return crc.getValue();
}
origin: aws/aws-sdk-java

private static long computePreludeCrc(ByteBuffer buf) {
  byte[] prelude = new byte[Prelude.LENGTH];
  buf.duplicate().get(prelude);
  Checksum crc = new CRC32();
  crc.update(prelude, 0, prelude.length);
  return crc.getValue();
}
origin: org.apache.poi/poi

/**
 * Calculate checksum on input data
 */
public static long calculateChecksum(byte[] data) {
  Checksum sum = new CRC32();
  sum.update(data, 0, data.length);
  return sum.getValue();
}
origin: plutext/docx4j

public static long calculateChecksum(byte[] data) {
  Checksum sum = new CRC32();
  sum.update(data, 0, data.length);
  return sum.getValue();
}
origin: apache/incubator-pinot

public long computeCrc()
  throws IOException {
 byte[] buffer = new byte[BUFFER_SIZE];
 Checksum checksum = new Adler32();
 for (File file : _files) {
  try (InputStream input = new FileInputStream(file)) {
   int len;
   while ((len = input.read(buffer)) > 0) {
    checksum.update(buffer, 0, len);
   }
  }
 }
 return checksum.getValue();
}
origin: org.apache.commons/commons-compress

/**
 * Reads from the stream into a byte array.
 * @throws IOException if the underlying stream throws or the
 * stream is exhausted and the Checksum doesn't match the expected
 * value
 */
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
  final int ret = in.read(b, off, len);
  if (ret >= 0) {
    checksum.update(b, off, ret);
    bytesRemaining -= ret;
  }
  if (bytesRemaining <= 0 && expectedChecksum != checksum.getValue()) {
    throw new IOException("Checksum verification failed");
  }
  return ret;
}
origin: org.apache.poi/poi

/**
 * Calculate checksum on all the data read from input stream.
 *
 * This should be more efficient than the equivalent code
 * {@code IOUtils.calculateChecksum(IOUtils.toByteArray(stream))}
 */
public static long calculateChecksum(InputStream stream) throws IOException {
  Checksum sum = new CRC32();
  byte[] buf = new byte[4096];
  int count;
  while ((count = stream.read(buf)) != -1) {
    if (count > 0) {
      sum.update(buf, 0, count);
    }
  }
  return sum.getValue();
}

origin: apache/flume

protected long calculateChecksum(byte[] body) {
 checksum.reset();
 checksum.update(body, 0, body.length);
 return checksum.getValue();
}
origin: org.apache.commons/commons-compress

/**
 * Reads a single byte from the stream
 * @throws IOException if the underlying stream throws or the
 * stream is exhausted and the Checksum doesn't match the expected
 * value
 */
@Override
public int read() throws IOException {
  if (bytesRemaining <= 0) {
    return -1;
  }
  final int ret = in.read();
  if (ret >= 0) {
    checksum.update(ret);
    --bytesRemaining;
  }
  if (bytesRemaining == 0 && expectedChecksum != checksum.getValue()) {
    throw new IOException("Checksum verification failed");
  }
  return ret;
}
origin: aws/aws-sdk-java

private void encodeOrThrow(OutputStream os) throws IOException {
  ByteArrayOutputStream headersAndPayload = new ByteArrayOutputStream();
  {
    DataOutputStream dos = new DataOutputStream(headersAndPayload);
    for (Entry<String, HeaderValue> entry : headers.entrySet()) {
      Header.encode(entry, dos);
    }
    dos.write(payload);
    dos.flush();
  }
  int totalLength = Prelude.LENGTH_WITH_CRC + headersAndPayload.size() + 4;
  {
    byte[] preludeBytes = getPrelude(totalLength);
    Checksum crc = new CRC32();
    crc.update(preludeBytes, 0, preludeBytes.length);
    DataOutputStream dos = new DataOutputStream(os);
    dos.write(preludeBytes);
    long value = crc.getValue();
    int value1 = (int) value;
    dos.writeInt(value1);
    dos.flush();
  }
  headersAndPayload.writeTo(os);
}
origin: apache/kafka

@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());
}
origin: apache/kafka

@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());
}
origin: apache/kafka

@Test
public void testUpdateInt() {
  final int value = 1000;
  final ByteBuffer buffer = ByteBuffer.allocate(4);
  buffer.putInt(value);
  Checksum crc1 = Crc32C.create();
  Checksum crc2 = Crc32C.create();
  Checksums.updateInt(crc1, value);
  crc2.update(buffer.array(), buffer.arrayOffset(), 4);
  assertEquals("Crc values should be the same", crc1.getValue(), crc2.getValue());
}
origin: apache/kafka

@Test
public void testUpdateLong() {
  final long value = Integer.MAX_VALUE + 1;
  final ByteBuffer buffer = ByteBuffer.allocate(8);
  buffer.putLong(value);
  Checksum crc1 = new Crc32();
  Checksum crc2 = new Crc32();
  Checksums.updateLong(crc1, value);
  crc2.update(buffer.array(), buffer.arrayOffset(), 8);
  assertEquals("Crc values should be the same", crc1.getValue(), crc2.getValue());
}
origin: Netflix/EVCache

private boolean checkCRCChecksum(byte[] data, final ChunkInfo ci, boolean hasZF) {
  if (data == null || data.length == 0) return false;
  final Checksum checksum = new CRC32();
  checksum.update(data, 0, data.length);
  final long currentChecksum = checksum.getValue();
  final long expectedChecksum = ci.getChecksum();
  if (log.isDebugEnabled()) log.debug("CurrentChecksum : " + currentChecksum + "; ExpectedChecksum : "
      + expectedChecksum + " for key : " + ci.getKey());
  if (currentChecksum != expectedChecksum) {
    if (!hasZF) {
      if (log.isWarnEnabled()) log.warn("CHECKSUM_ERROR : Chunks : " + ci.getChunks() + " ; "
          + "currentChecksum : " + currentChecksum + "; expectedChecksum : " + expectedChecksum
          + " for key : " + ci.getKey());
      EVCacheMetricsFactory.increment(appName + "-CHECK_SUM_ERROR");
    }
    return false;
  }
  return true;
}
origin: commons-codec/commons-codec

 @Override
 public void run() {
  final long st = System.nanoTime();
  crc.reset();
  for (int i = 0; i < trials; i++) {
   crc.update(bytes, 0, size);
  }
  final long et = System.nanoTime();
  final double secsElapsed = (et - st) / 1000000000.0d;
  results[index] = new BenchResult(crc.getValue(), mbProcessed/secsElapsed);
 }
};
origin: netty/netty

if (hasChecksum && checksum != null) {
  checksum.reset();
  checksum.update(output, outputPtr, originalLength);
  final int checksumResult = (int) checksum.getValue();
  if (checksumResult != currentChecksum) {
    throw new DecompressionException(String.format(
origin: greenrobot/essentials

@Test
public void testGetValueStable() {
  checksum.update(INPUT16, 0, INPUT16.length);
  long hash = checksum.getValue();
  // Calling checksum.getValue() twice should not change hash
  Assert.assertEquals(hash, checksum.getValue());
}
origin: commons-io/commons-io

@Test
public void testChecksumCRC32() throws Exception {
  // create a test file
  final String text = "Imagination is more important than knowledge - Einstein";
  final File file = new File(getTestDirectory(), "checksum-test.txt");
  FileUtils.writeStringToFile(file, text, "US-ASCII");
  // compute the expected checksum
  final Checksum expectedChecksum = new CRC32();
  expectedChecksum.update(text.getBytes("US-ASCII"), 0, text.length());
  final long expectedValue = expectedChecksum.getValue();
  // compute the checksum of the file
  final long resultValue = FileUtils.checksumCRC32(file);
  assertEquals(expectedValue, resultValue);
}
origin: commons-io/commons-io

@Test
public void testChecksum() throws Exception {
  // create a test file
  final String text = "Imagination is more important than knowledge - Einstein";
  final File file = new File(getTestDirectory(), "checksum-test.txt");
  FileUtils.writeStringToFile(file, text, "US-ASCII");
  // compute the expected checksum
  final Checksum expectedChecksum = new CRC32();
  expectedChecksum.update(text.getBytes("US-ASCII"), 0, text.length());
  final long expectedValue = expectedChecksum.getValue();
  // compute the checksum of the file
  final Checksum testChecksum = new CRC32();
  final Checksum resultChecksum = FileUtils.checksum(file, testChecksum);
  final long resultValue = resultChecksum.getValue();
  assertSame(testChecksum, resultChecksum);
  assertEquals(expectedValue, resultValue);
}
java.util.zipChecksumgetValue

Javadoc

Returns the current calculated checksum value.

Popular methods of Checksum

  • update
    Updates the checksum with the given bytes.
  • reset
    Resets the checksum value applied before beginning calculations on a new stream of data.

Popular in Java

  • Reading from database using SQL prepared statement
  • compareTo (BigDecimal)
  • onRequestPermissionsResult (Fragment)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • JPanel (javax.swing)
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now