1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.filter;
22
23 import org.apache.hadoop.hbase.KeyValue;
24 import org.apache.hadoop.hbase.util.Bytes;
25
26 import java.io.DataInput;
27 import java.io.DataOutput;
28 import java.io.IOException;
29 import java.util.List;
30 import java.util.ArrayList;
31
32 import com.google.common.base.Preconditions;
33
34
35
36
37
38
39
40 public class InclusiveStopFilter extends FilterBase {
41 private byte [] stopRowKey;
42 private boolean done = false;
43
44 public InclusiveStopFilter() {
45 super();
46 }
47
48 public InclusiveStopFilter(final byte [] stopRowKey) {
49 this.stopRowKey = stopRowKey;
50 }
51
52 public byte[] getStopRowKey() {
53 return this.stopRowKey;
54 }
55
56 public boolean filterRowKey(byte[] buffer, int offset, int length) {
57 if (buffer == null) {
58
59 if (this.stopRowKey == null) {
60 return true;
61 }
62 return false;
63 }
64
65 int cmp = Bytes.compareTo(stopRowKey, 0, stopRowKey.length,
66 buffer, offset, length);
67
68 if(cmp < 0) {
69 done = true;
70 }
71 return done;
72 }
73
74 public boolean filterAllRemaining() {
75 return done;
76 }
77
78 public static Filter createFilterFromArguments (ArrayList<byte []> filterArguments) {
79 Preconditions.checkArgument(filterArguments.size() == 1,
80 "Expected 1 but got: %s", filterArguments.size());
81 byte [] stopRowKey = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0));
82 return new InclusiveStopFilter(stopRowKey);
83 }
84
85 public void write(DataOutput out) throws IOException {
86 Bytes.writeByteArray(out, this.stopRowKey);
87 }
88
89 public void readFields(DataInput in) throws IOException {
90 this.stopRowKey = Bytes.readByteArray(in);
91 }
92
93 @Override
94 public String toString() {
95 return this.getClass().getSimpleName() + " " + Bytes.toStringBinary(this.stopRowKey);
96 }
97 }