1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.io.hfile;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.HConstants;
22 import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
23 import org.apache.hadoop.hbase.io.crypto.Encryption;
24 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
25 import org.apache.hadoop.hbase.util.ChecksumType;
26
27
28
29
30 @InterfaceAudience.Private
31 public class HFileContextBuilder {
32
33 public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
34
35
36 private boolean usesHBaseChecksum = true;
37
38 private boolean includesMvcc = true;
39
40 private boolean includesTags = false;
41
42 private Algorithm compression = Algorithm.NONE;
43
44 private boolean compressTags = false;
45
46 private ChecksumType checksumType = ChecksumType.getDefaultChecksumType();
47
48 private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM;
49
50 private int blocksize = HConstants.DEFAULT_BLOCKSIZE;
51 private DataBlockEncoding encoding = DataBlockEncoding.NONE;
52
53 private Encryption.Context cryptoContext = Encryption.Context.NONE;
54 private long fileCreateTime = 0;
55
56 private String hfileName = null;
57
58 public HFileContextBuilder() {}
59
60
61
62
63 public HFileContextBuilder(final HFileContext hfc) {
64 this.usesHBaseChecksum = hfc.isUseHBaseChecksum();
65 this.includesMvcc = hfc.isIncludesMvcc();
66 this.includesTags = hfc.isIncludesTags();
67 this.compression = hfc.getCompression();
68 this.compressTags = hfc.isCompressTags();
69 this.checksumType = hfc.getChecksumType();
70 this.bytesPerChecksum = hfc.getBytesPerChecksum();
71 this.blocksize = hfc.getBlocksize();
72 this.encoding = hfc.getDataBlockEncoding();
73 this.cryptoContext = hfc.getEncryptionContext();
74 this.fileCreateTime = hfc.getFileCreateTime();
75 this.hfileName = hfc.getHFileName();
76 }
77
78 public HFileContextBuilder withHBaseCheckSum(boolean useHBaseCheckSum) {
79 this.usesHBaseChecksum = useHBaseCheckSum;
80 return this;
81 }
82
83 public HFileContextBuilder withIncludesMvcc(boolean includesMvcc) {
84 this.includesMvcc = includesMvcc;
85 return this;
86 }
87
88 public HFileContextBuilder withIncludesTags(boolean includesTags) {
89 this.includesTags = includesTags;
90 return this;
91 }
92
93 public HFileContextBuilder withCompression(Algorithm compression) {
94 this.compression = compression;
95 return this;
96 }
97
98 public HFileContextBuilder withCompressTags(boolean compressTags) {
99 this.compressTags = compressTags;
100 return this;
101 }
102
103 public HFileContextBuilder withChecksumType(ChecksumType checkSumType) {
104 this.checksumType = checkSumType;
105 return this;
106 }
107
108 public HFileContextBuilder withBytesPerCheckSum(int bytesPerChecksum) {
109 this.bytesPerChecksum = bytesPerChecksum;
110 return this;
111 }
112
113 public HFileContextBuilder withBlockSize(int blockSize) {
114 this.blocksize = blockSize;
115 return this;
116 }
117
118 public HFileContextBuilder withDataBlockEncoding(DataBlockEncoding encoding) {
119 this.encoding = encoding;
120 return this;
121 }
122
123 public HFileContextBuilder withEncryptionContext(Encryption.Context cryptoContext) {
124 this.cryptoContext = cryptoContext;
125 return this;
126 }
127
128 public HFileContextBuilder withCreateTime(long fileCreateTime) {
129 this.fileCreateTime = fileCreateTime;
130 return this;
131 }
132
133 public HFileContextBuilder withHFileName(String name) {
134 this.hfileName = name;
135 return this;
136 }
137
138 public HFileContext build() {
139 return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression,
140 compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext,
141 fileCreateTime, hfileName);
142 }
143 }