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

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

Best Java code snippets using java.util.zip.Checksum.update (Showing top 20 results out of 1,890)

Refine searchRefine arrow

  • Checksum.getValue
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: greenrobot/essentials

@Test
public void testMixedUnaligned() {
  checksum.update(INPUT16, 0, INPUT16.length);
  long hash = checksum.getValue();
  checksum.reset();
  checksum.update(INPUT16, 0, 2);
  checksum.update(INPUT16[2]);
  checksum.update(INPUT16, 3, 11);
  checksum.update(INPUT16[14]);
  checksum.update(INPUT16[15]);
  Assert.assertEquals(hash, checksum.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 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: 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: 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: 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

public void testExpectedHash(long expectedFor0, long expectedForInput4, long expectedForInput16) {
  checksum.update(0);
  checksum.update(0);
  checksum.update(0);
  checksum.update(0);
  Assert.assertEquals("0 (int)", expectedFor0, checksum.getValue());
  checksum.reset();
  checksum.update(INPUT4, 0, INPUT4.length);
  Assert.assertEquals("I4", expectedForInput4, checksum.getValue());
  checksum.reset();
  checksum.update(INPUT16, 0, INPUT16.length);
  Assert.assertEquals("I16", expectedForInput16, 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: 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());
}
java.util.zipChecksumupdate

Javadoc

Updates the checksum value with the given byte.

Popular methods of Checksum

  • getValue
    Returns the current calculated checksum value.
  • reset
    Resets the checksum value applied before beginning calculations on a new stream of data.

Popular in Java

  • Updating database using SQL prepared statement
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getContentResolver (Context)
  • getSupportFragmentManager (FragmentActivity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • String (java.lang)
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top plugins for Android Studio
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