1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hbase.cell;
20
21 import java.nio.ByteBuffer;
22
23 import org.apache.hadoop.classification.InterfaceAudience;
24 import org.apache.hadoop.classification.InterfaceStability;
25 import org.apache.hadoop.hbase.util.ByteRange;
26 import org.apache.hbase.Cell;
27
28 @InterfaceAudience.Private
29 @InterfaceStability.Evolving
30 public final class CellTool {
31
32
33
34 public static ByteRange fillRowRange(Cell cell, ByteRange range) {
35 return range.set(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
36 }
37
38 public static ByteRange fillFamilyRange(Cell cell, ByteRange range) {
39 return range.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
40 }
41
42 public static ByteRange fillQualifierRange(Cell cell, ByteRange range) {
43 return range.set(cell.getQualifierArray(), cell.getQualifierOffset(),
44 cell.getQualifierLength());
45 }
46
47
48
49
50 public static byte[] getRowArray(Cell cell){
51 byte[] output = new byte[cell.getRowLength()];
52 copyRowTo(cell, output, 0);
53 return output;
54 }
55
56 public static byte[] getFamilyArray(Cell cell){
57 byte[] output = new byte[cell.getFamilyLength()];
58 copyFamilyTo(cell, output, 0);
59 return output;
60 }
61
62 public static byte[] getQualifierArray(Cell cell){
63 byte[] output = new byte[cell.getQualifierLength()];
64 copyQualifierTo(cell, output, 0);
65 return output;
66 }
67
68 public static byte[] getValueArray(Cell cell){
69 byte[] output = new byte[cell.getValueLength()];
70 copyValueTo(cell, output, 0);
71 return output;
72 }
73
74
75
76
77 public static int copyRowTo(Cell cell, byte[] destination, int destinationOffset) {
78 System.arraycopy(cell.getRowArray(), cell.getRowOffset(), destination, destinationOffset,
79 cell.getRowLength());
80 return destinationOffset + cell.getRowLength();
81 }
82
83 public static int copyFamilyTo(Cell cell, byte[] destination, int destinationOffset) {
84 System.arraycopy(cell.getFamilyArray(), cell.getFamilyOffset(), destination, destinationOffset,
85 cell.getFamilyLength());
86 return destinationOffset + cell.getFamilyLength();
87 }
88
89 public static int copyQualifierTo(Cell cell, byte[] destination, int destinationOffset) {
90 System.arraycopy(cell.getQualifierArray(), cell.getQualifierOffset(), destination,
91 destinationOffset, cell.getQualifierLength());
92 return destinationOffset + cell.getQualifierLength();
93 }
94
95 public static int copyValueTo(Cell cell, byte[] destination, int destinationOffset) {
96 System.arraycopy(cell.getValueArray(), cell.getValueOffset(), destination, destinationOffset,
97 cell.getValueLength());
98 return destinationOffset + cell.getValueLength();
99 }
100
101
102
103
104 public static byte getRowByte(Cell cell, int index) {
105 return cell.getRowArray()[cell.getRowOffset() + index];
106 }
107
108
109
110
111 public static ByteBuffer getValueBufferShallowCopy(Cell cell) {
112 ByteBuffer buffer = ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(),
113 cell.getValueLength());
114
115 return buffer;
116 }
117
118 }