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
;
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.
33 * Designed to be a slimmed-down, mutable alternative to {@link java.nio.ByteBuffer}.
36 @InterfaceAudience.Public
37 public interface PositionedByteRange
extends ByteRange
{
39 // net new API is here.
42 * The current {@code position} marker. This valuae is 0-indexed, relative to
43 * the beginning of the range.
45 public int getPosition();
48 * Update the {@code position} index. May not be greater than {@code length}.
49 * @param position the new position in this range.
52 public PositionedByteRange
setPosition(int position
);
55 * The number of bytes remaining between position and the end of the range.
57 public int getRemaining();
60 * Retrieve the next byte from this range without incrementing position.
65 * Retrieve the next byte from this range.
70 * Retrieve the next short value from this range.
72 public short getShort();
75 * Retrieve the next int value from this range.
80 * Retrieve the next long value from this range.
82 public long getLong();
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();
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.
97 public PositionedByteRange
get(byte[] dst
);
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}.
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.
116 public PositionedByteRange
put(byte val
);
119 * Store short {@code val} at the next position in this range.
120 * @param val the new value.
123 public PositionedByteRange
putShort(short val
);
126 * Store int {@code val} at the next position in this range.
127 * @param val the new value.
130 public PositionedByteRange
putInt(int val
);
133 * Store long {@code val} at the next position in this range.
134 * @param val the new value.
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.
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}.
162 public PositionedByteRange
put(byte[] val
, int offset
, int length
);
165 * Limits the byte range upto a specified value. Limit cannot be greater than
169 * @return PositionedByteRange
171 public PositionedByteRange
setLimit(int limit
);
174 * Return the current limit
178 public int getLimit();
180 // override parent interface declarations to return this interface.
183 public PositionedByteRange
unset();
186 public PositionedByteRange
set(int capacity
);
189 public PositionedByteRange
set(byte[] bytes
);
192 public PositionedByteRange
set(byte[] bytes
, int offset
, int length
);
195 public PositionedByteRange
setOffset(int offset
);
198 public PositionedByteRange
setLength(int length
);
201 public PositionedByteRange
get(int index
, byte[] dst
);
204 public PositionedByteRange
get(int index
, byte[] dst
, int offset
, int length
);
207 public PositionedByteRange
put(int index
, byte val
);
210 public PositionedByteRange
putShort(int index
, short val
);
213 public PositionedByteRange
putInt(int index
, int val
);
216 public PositionedByteRange
putLong(int index
, long val
);
219 public PositionedByteRange
put(int index
, byte[] val
);
222 public PositionedByteRange
put(int index
, byte[] val
, int offset
, int length
);
225 public PositionedByteRange
deepCopy();
228 public PositionedByteRange
shallowCopy();
231 public PositionedByteRange
shallowCopySubRange(int innerOffset
, int copyLength
);