Top Description Methods
java.util.zip

public Interface Checksum

Known Direct Implementers
java.util.zip.CRC32, java.util.zip.CRC32C, java.util.zip.Adler32
Imports
java.nio.ByteBuffer

An interface representing a data checksum.
Author
David Connelly
Since
1.1

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the current checksum value
getValue
()

Returns the current checksum value.

public void
reset()

Resets the checksum to its initial value.

public void
update(int
the byte to update the checksum with
b
)

Updates the current checksum with the specified byte.

public default void
update(byte[]
the array of bytes to update the checksum with
b
)

Updates the current checksum with the specified array of bytes.

public void
update(byte[]
the byte array to update the checksum with
b
,
int
the start offset of the data
off
,
int
the number of bytes to use for the update
len
)

Updates the current checksum with the specified array of bytes.

public default void
update(ByteBuffer
the ByteBuffer to update the checksum with
buffer
)

Updates the current checksum with the bytes from the specified buffer.

Method Detail

getValueback to summary
public long getValue()

Returns the current checksum value.

Returns:long

the current checksum value

resetback to summary
public void reset()

Resets the checksum to its initial value.

updateback to summary
public void update(int b)

Updates the current checksum with the specified byte.

Parameters
b:int

the byte to update the checksum with

updateback to summary
public default void update(byte[] b)

Updates the current checksum with the specified array of bytes.

Implementation Specification

This default implementation is equal to calling update(b, 0, b.length).

Parameters
b:byte[]

the array of bytes to update the checksum with

Exceptions
NullPointerException:
if b is null
Since
9
updateback to summary
public 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

updateback to summary
public default 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 Specification

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

Exceptions
NullPointerException:
if buffer is null
Since
9