-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathChecksumAlgorithm.java
More file actions
94 lines (71 loc) · 2.63 KB
/
ChecksumAlgorithm.java
File metadata and controls
94 lines (71 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
package software.amazon.awssdk.crt.s3;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.List;
public enum ChecksumAlgorithm {
NONE(0),
CRC32C(1),
CRC32(2),
SHA1(3),
SHA256(4),
CRC64NVME(5),
SHA512(6),
XXHASH64(7),
XXHASH3(8),
XXHASH128(9),
MD5(10);
ChecksumAlgorithm(int nativeValue) {
this.nativeValue = nativeValue;
}
public int getNativeValue() {
return nativeValue;
}
public static ChecksumAlgorithm getEnumValueFromInteger(int value) {
ChecksumAlgorithm enumValue = enumMapping.get(value);
if (enumValue != null) {
return enumValue;
}
throw new RuntimeException("Invalid S3 Meta Request type");
}
private static Map<Integer, ChecksumAlgorithm> buildEnumMapping() {
Map<Integer, ChecksumAlgorithm> enumMapping = new HashMap<Integer, ChecksumAlgorithm>();
enumMapping.put(NONE.getNativeValue(), NONE);
enumMapping.put(CRC32C.getNativeValue(), CRC32C);
enumMapping.put(CRC32.getNativeValue(), CRC32);
enumMapping.put(SHA1.getNativeValue(), SHA1);
enumMapping.put(SHA256.getNativeValue(), SHA256);
enumMapping.put(CRC64NVME.getNativeValue(), CRC64NVME);
enumMapping.put(SHA512.getNativeValue(), SHA512);
enumMapping.put(XXHASH64.getNativeValue(), XXHASH64);
enumMapping.put(XXHASH3.getNativeValue(), XXHASH3);
enumMapping.put(XXHASH128.getNativeValue(), XXHASH128);
enumMapping.put(MD5.getNativeValue(), MD5);
return enumMapping;
}
private int nativeValue;
private static Map<Integer, ChecksumAlgorithm> enumMapping = buildEnumMapping();
private static int[] algorithmsListToIntArray(final List<ChecksumAlgorithm> algorithms) {
ArrayList<Integer> intList = new ArrayList<>();
algorithms.forEach((algorithm) -> {
intList.add(algorithm.getNativeValue());
});
return intList.stream()
.mapToInt(Integer::intValue)
.toArray();
}
/**
* @hidden Marshals a list of algorithm into an array for Jni to deal with
*
* @param algorithms list of algorithms
* @return a int[] that with the [algorithms.nativeValue, *]
*/
public static int[] marshallAlgorithmsForJNI(final List<ChecksumAlgorithm> algorithms) {
return Optional.ofNullable(algorithms).map(ChecksumAlgorithm::algorithmsListToIntArray).orElse(null);
}
}