Stay organized with collections
Save and categorize content based on your preferences.
Checksum
public
interface
Checksum
Known indirect subclasses
Adler32 |
A class that can be used to compute the Adler-32 checksum of a data
stream.
|
CRC32 |
A class that can be used to compute the CRC-32 of a data stream.
|
CRC32C |
A class that can be used to compute the CRC-32C of a data stream.
|
|
An interface representing a data checksum.
Summary
Public methods |
abstract
long
|
getValue()
Returns the current checksum value.
|
abstract
void
|
reset()
Resets the checksum to its initial value.
|
default
void
|
update(byte[] b)
Updates the current checksum with the specified array of bytes.
|
default
void
|
update(ByteBuffer buffer)
Updates the current checksum with the bytes from the specified buffer.
|
abstract
void
|
update(byte[] b, int off, int len)
Updates the current checksum with the specified array of bytes.
|
abstract
void
|
update(int b)
Updates the current checksum with the specified byte.
|
Public methods
getValue
public abstract long getValue ()
Returns the current checksum value.
Returns |
long |
the current checksum value |
reset
public abstract void reset ()
Resets the checksum to its initial value.
update
public void update (byte[] b)
Updates the current checksum with the specified array of bytes.
Implementation Requirements:
- This default implementation is equal to calling
update(b, 0, b.length)
.
Parameters |
b |
byte : the array of bytes to update the checksum with |
update
public void update (ByteBuffer buffer)
Updates the current checksum with the bytes from the specified buffer.
The checksum is updated with the remaining bytes in the buffer, starting
at the buffer's position. Upon return, the buffer's position will be
updated to its limit; its limit will not have been changed.
API Note:
- For best performance with DirectByteBuffer and other ByteBuffer
implementations without a backing array implementers of this interface
should override this method.
Implementation Requirements:
- The default implementation has the following behavior.
For ByteBuffers backed by an accessible byte array.
update(buffer.array(),
buffer.position() + buffer.arrayOffset(),
buffer.remaining());
For ByteBuffers not backed by an accessible byte array.
byte[] b = new byte[Math.min(buffer.remaining(), 4096)];
while (buffer.hasRemaining()) {
int length = Math.min(buffer.remaining(), b.length);
buffer.get(b, 0, length);
update(b, 0, length);
}
Parameters |
buffer |
ByteBuffer : the ByteBuffer to update the checksum with |
update
public abstract void update (byte[] b,
int off,
int len)
Updates the current checksum with the specified array of bytes.
Parameters |
b |
byte : the byte array to update the checksum with |
off |
int : the start offset of the data |
len |
int : the number of bytes to use for the update |
update
public abstract void update (int b)
Updates the current checksum with the specified byte.
Parameters |
b |
int : the byte to update the checksum with |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# Checksum\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nChecksum\n========\n\n\n`\npublic\n\n\ninterface\nChecksum\n`\n\n\n`\n\n\n`\n\n|------------------------|\n| java.util.zip.Checksum |\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [Adler32](/reference/java/util/zip/Adler32), [CRC32](/reference/java/util/zip/CRC32), [CRC32C](/reference/java/util/zip/CRC32C) |---------------------------------------------|-----------------------------------------------------------------------------| | [Adler32](/reference/java/util/zip/Adler32) | A class that can be used to compute the Adler-32 checksum of a data stream. | | [CRC32](/reference/java/util/zip/CRC32) | A class that can be used to compute the CRC-32 of a data stream. | | [CRC32C](/reference/java/util/zip/CRC32C) | A class that can be used to compute the CRC-32C of a data stream. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nAn interface representing a data checksum.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract long` | ` `[getValue](/reference/java/util/zip/Checksum#getValue())`() ` Returns the current checksum value. |\n| ` abstract void` | ` `[reset](/reference/java/util/zip/Checksum#reset())`() ` Resets the checksum to its initial value. |\n| ` default void` | ` `[update](/reference/java/util/zip/Checksum#update(byte[]))`(byte[] b) ` Updates the current checksum with the specified array of bytes. |\n| ` default void` | ` `[update](/reference/java/util/zip/Checksum#update(java.nio.ByteBuffer))`(`[ByteBuffer](/reference/java/nio/ByteBuffer)` buffer) ` Updates the current checksum with the bytes from the specified buffer. |\n| ` abstract void` | ` `[update](/reference/java/util/zip/Checksum#update(byte[],%20int,%20int))`(byte[] b, int off, int len) ` Updates the current checksum with the specified array of bytes. |\n| ` abstract void` | ` `[update](/reference/java/util/zip/Checksum#update(int))`(int b) ` Updates the current checksum with the specified byte. |\n\nPublic methods\n--------------\n\n### getValue\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract long getValue ()\n```\n\nReturns the current checksum value.\n\n\u003cbr /\u003e\n\n| Returns ||\n|--------|-----------------------------------|\n| `long` | the current checksum value \u003cbr /\u003e |\n\n### reset\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void reset ()\n```\n\nResets the checksum to its initial value.\n\n\u003cbr /\u003e\n\n### update\n\nAdded in [API level 34](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic void update (byte[] b)\n```\n\nUpdates the current checksum with the specified array of bytes.\n\n\u003cbr /\u003e\n\n##### Implementation Requirements:\n\n- This default implementation is equal to calling `update(b, 0, b.length)`.\n\n| Parameters ||\n|-----|---------------------------------------------------------------|\n| `b` | `byte`: the array of bytes to update the checksum with \u003cbr /\u003e |\n\n| Throws ||\n|-------------------------------------------------------------------|------------------|\n| [NullPointerException](/reference/java/lang/NullPointerException) | if `b` is `null` |\n\n### update\n\nAdded in [API level 34](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic void update (ByteBuffer buffer)\n```\n\nUpdates the current checksum with the bytes from the specified buffer.\n\nThe checksum is updated with the remaining bytes in the buffer, starting\nat the buffer's position. Upon return, the buffer's position will be\nupdated to its limit; its limit will not have been changed.\n\n\u003cbr /\u003e\n\n##### API Note:\n\n- For best performance with DirectByteBuffer and other ByteBuffer implementations without a backing array implementers of this interface should override this method. \n\n##### Implementation Requirements:\n\n- The default implementation has the following behavior. \n For ByteBuffers backed by an accessible byte array. \n\n update(buffer.array(),\n buffer.position() + buffer.arrayOffset(),\n buffer.remaining());\n \n For ByteBuffers not backed by an accessible byte array. \n\n byte[] b = new byte[Math.min(buffer.remaining(), 4096)];\n while (buffer.hasRemaining()) {\n int length = Math.min(buffer.remaining(), b.length);\n buffer.get(b, 0, length);\n update(b, 0, length);\n }\n \n| Parameters ||\n|----------|-----------------------------------------------------------------|\n| `buffer` | `ByteBuffer`: the ByteBuffer to update the checksum with \u003cbr /\u003e |\n\n| Throws ||\n|-------------------------------------------------------------------|-----------------------|\n| [NullPointerException](/reference/java/lang/NullPointerException) | if `buffer` is `null` |\n\n### update\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void update (byte[] b, \n int off, \n int len)\n```\n\nUpdates the current checksum with the specified array of bytes.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-------|-----------------------------------------------------------|\n| `b` | `byte`: the byte array to update the checksum with \u003cbr /\u003e |\n| `off` | `int`: the start offset of the data \u003cbr /\u003e |\n| `len` | `int`: the number of bytes to use for the update \u003cbr /\u003e |\n\n### update\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void update (int b)\n```\n\nUpdates the current checksum with the specified byte.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|----------------------------------------------------|\n| `b` | `int`: the byte to update the checksum with \u003cbr /\u003e |"]]