1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.util;
20
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.util.DataChecksum;
23
24
25
26
27
28
29
30 @InterfaceAudience.Private
31 public enum ChecksumType {
32
33 NULL((byte)0) {
34 @Override
35 public String getName() {
36 return "NULL";
37 }
38
39 @Override public DataChecksum.Type getDataChecksumType() {
40 return DataChecksum.Type.NULL;
41 }
42 },
43
44 CRC32((byte)1) {
45 @Override
46 public String getName() {
47 return "CRC32";
48 }
49
50 @Override public DataChecksum.Type getDataChecksumType() {
51 return DataChecksum.Type.CRC32;
52 }
53 },
54
55 CRC32C((byte)2) {
56 @Override
57 public String getName() {
58 return "CRC32C";
59 }
60
61 @Override public DataChecksum.Type getDataChecksumType() {
62 return DataChecksum.Type.CRC32C;
63 }
64 };
65
66 private final byte code;
67
68 public static ChecksumType getDefaultChecksumType() {
69 return ChecksumType.CRC32C;
70 }
71
72
73 public abstract String getName();
74
75
76 public abstract DataChecksum.Type getDataChecksumType();
77
78 private ChecksumType(final byte c) {
79 this.code = c;
80 }
81
82 public byte getCode() {
83 return this.code;
84 }
85
86
87
88
89
90
91
92 public static ChecksumType codeToType(final byte b) {
93 for (ChecksumType t : ChecksumType.values()) {
94 if (t.getCode() == b) {
95 return t;
96 }
97 }
98 throw new RuntimeException("Unknown checksum type code " + b);
99 }
100
101
102
103
104
105
106
107 public static ChecksumType nameToType(final String name) {
108 for (ChecksumType t : ChecksumType.values()) {
109 if (t.getName().equals(name)) {
110 return t;
111 }
112 }
113 throw new RuntimeException("Unknown checksum type name " + name);
114 }
115 }