HBASE-24163 MOB compactor implementations should use format specifiers when calling...
[hbase.git] / hbase-common / src / main / java / org / apache / hadoop / hbase / util / PositionedByteRange.java
blob617c0e27f6eeaa6cf2a16b41d4ca622d053ca765
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.apache.hadoop.hbase.util;
22 import org.apache.yetus.audience.InterfaceAudience;
24 /**
25 * <p>
26 * Extends {@link ByteRange} with additional methods to support tracking a
27 * consumers position within the viewport. The API is extended with methods
28 * {@link #get()} and {@link #put(byte)} for interacting with the backing
29 * array from the current position forward. This frees the caller from managing
30 * their own index into the array.
31 * </p>
32 * <p>
33 * Designed to be a slimmed-down, mutable alternative to {@link java.nio.ByteBuffer}.
34 * </p>
36 @InterfaceAudience.Public
37 public interface PositionedByteRange extends ByteRange {
39 // net new API is here.
41 /**
42 * The current {@code position} marker. This valuae is 0-indexed, relative to
43 * the beginning of the range.
45 public int getPosition();
47 /**
48 * Update the {@code position} index. May not be greater than {@code length}.
49 * @param position the new position in this range.
50 * @return this.
52 public PositionedByteRange setPosition(int position);
54 /**
55 * The number of bytes remaining between position and the end of the range.
57 public int getRemaining();
59 /**
60 * Retrieve the next byte from this range without incrementing position.
62 public byte peek();
64 /**
65 * Retrieve the next byte from this range.
67 public byte get();
69 /**
70 * Retrieve the next short value from this range.
72 public short getShort();
74 /**
75 * Retrieve the next int value from this range.
77 public int getInt();
79 /**
80 * Retrieve the next long value from this range.
82 public long getLong();
84 /**
85 * Retrieve the next long value, which is stored as VLong, from this range
86 * @return the long value which is stored as VLong
88 public long getVLong();
90 /**
91 * Fill {@code dst} with bytes from the range, starting from {@code position}.
92 * This range's {@code position} is incremented by the length of {@code dst},
93 * the number of bytes copied.
94 * @param dst the destination of the copy.
95 * @return this.
97 public PositionedByteRange get(byte[] dst);
99 /**
100 * Fill {@code dst} with bytes from the range, starting from the current
101 * {@code position}. {@code length} bytes are copied into {@code dst},
102 * starting at {@code offset}. This range's {@code position} is incremented
103 * by the number of bytes copied.
104 * @param dst the destination of the copy.
105 * @param offset the offset into {@code dst} to start the copy.
106 * @param length the number of bytes to copy into {@code dst}.
107 * @return this.
109 public PositionedByteRange get(byte[] dst, int offset, int length);
112 * Store {@code val} at the next position in this range.
113 * @param val the new value.
114 * @return this.
116 public PositionedByteRange put(byte val);
119 * Store short {@code val} at the next position in this range.
120 * @param val the new value.
121 * @return this.
123 public PositionedByteRange putShort(short val);
126 * Store int {@code val} at the next position in this range.
127 * @param val the new value.
128 * @return this.
130 public PositionedByteRange putInt(int val);
133 * Store long {@code val} at the next position in this range.
134 * @param val the new value.
135 * @return this.
137 public PositionedByteRange putLong(long val);
140 * Store the long {@code val} at the next position as a VLong
141 * @param val the value to store
142 * @return number of bytes written
144 public int putVLong(long val);
147 * Store the content of {@code val} in this range, starting at the next position.
148 * @param val the new value.
149 * @return this.
151 public PositionedByteRange put(byte[] val);
154 * Store {@code length} bytes from {@code val} into this range. Bytes from
155 * {@code val} are copied starting at {@code offset} into the range, starting at
156 * the current position.
157 * @param val the new value.
158 * @param offset the offset in {@code val} from which to start copying.
159 * @param length the number of bytes to copy from {@code val}.
160 * @return this.
162 public PositionedByteRange put(byte[] val, int offset, int length);
165 * Limits the byte range upto a specified value. Limit cannot be greater than
166 * capacity
168 * @param limit
169 * @return PositionedByteRange
171 public PositionedByteRange setLimit(int limit);
174 * Return the current limit
176 * @return limit
178 public int getLimit();
180 // override parent interface declarations to return this interface.
182 @Override
183 public PositionedByteRange unset();
185 @Override
186 public PositionedByteRange set(int capacity);
188 @Override
189 public PositionedByteRange set(byte[] bytes);
191 @Override
192 public PositionedByteRange set(byte[] bytes, int offset, int length);
194 @Override
195 public PositionedByteRange setOffset(int offset);
197 @Override
198 public PositionedByteRange setLength(int length);
200 @Override
201 public PositionedByteRange get(int index, byte[] dst);
203 @Override
204 public PositionedByteRange get(int index, byte[] dst, int offset, int length);
206 @Override
207 public PositionedByteRange put(int index, byte val);
209 @Override
210 public PositionedByteRange putShort(int index, short val);
212 @Override
213 public PositionedByteRange putInt(int index, int val);
215 @Override
216 public PositionedByteRange putLong(int index, long val);
218 @Override
219 public PositionedByteRange put(int index, byte[] val);
221 @Override
222 public PositionedByteRange put(int index, byte[] val, int offset, int length);
224 @Override
225 public PositionedByteRange deepCopy();
227 @Override
228 public PositionedByteRange shallowCopy();
230 @Override
231 public PositionedByteRange shallowCopySubRange(int innerOffset, int copyLength);