-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c48ca0
commit 5587af4
Showing
3 changed files
with
129 additions
and
14 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/main/java/software/amazon/awssdk/crt/checksums/CRC64NVME.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
package software.amazon.awssdk.crt.checksums; | ||
|
||
import software.amazon.awssdk.crt.CRT; | ||
import java.util.zip.Checksum; | ||
|
||
/** | ||
* CRT implementation of the Java Checksum interface for making CRC64NVME checksum calculations | ||
*/ | ||
public class CRC64NVME implements Checksum, Cloneable { | ||
static { | ||
new CRT(); | ||
}; | ||
|
||
private int value = 0; | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
public CRC64NVME() { | ||
} | ||
|
||
private CRC64NVME(int value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Object clone() { | ||
return new CRC64NVME(value); | ||
} | ||
|
||
/** | ||
* Returns the current checksum value. | ||
* | ||
* @return the current checksum value. | ||
*/ | ||
@Override | ||
public long getValue() { | ||
return (long) value & 0xffffffffffffffffL; | ||
} | ||
|
||
/** | ||
* Resets the checksum to its initial value. | ||
*/ | ||
@Override | ||
public void reset() { | ||
value = 0; | ||
} | ||
|
||
/** | ||
* Updates the current checksum with the specified array of bytes. | ||
* | ||
* @param b the byte array to update the checksum with | ||
* @param off the starting offset within b of the data to use | ||
* @param len the number of bytes to use in the update | ||
*/ | ||
@Override | ||
public void update(byte[] b, int off, int len) { | ||
if (b == null) { | ||
throw new NullPointerException(); | ||
} | ||
if (off < 0 || len < 0 || off > b.length - len) { | ||
throw new ArrayIndexOutOfBoundsException(); | ||
} | ||
value = crc64nvme(b, value, off, len); | ||
} | ||
|
||
/** | ||
* Updates the current checksum with the specified array of bytes. | ||
* | ||
* @param b the byte array to update the checksum with | ||
*/ | ||
public void update(byte[] b) { | ||
update(b, 0, b.length); | ||
} | ||
|
||
/** | ||
* Updates the current checksum with the specified byte. | ||
* | ||
* @param b the byte to update the checksum with | ||
*/ | ||
@Override | ||
public void update(int b) { | ||
if (b < 0 || b > 0xff) { | ||
throw new IllegalArgumentException(); | ||
} | ||
byte[] buf = { (byte) (b & 0x000000ff) }; | ||
this.update(buf); | ||
} | ||
|
||
/******************************************************************************* | ||
* native methods | ||
******************************************************************************/ | ||
private static native int crc64nvme(byte[] input, int previous, int offset, int length);; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters