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.
18 package org
.apache
.hadoop
.hbase
.util
;
20 import org
.apache
.yetus
.audience
.InterfaceAudience
;
23 * A read only version of the {@link ByteRange}.
25 @InterfaceAudience.Public
26 public class SimpleByteRange
extends AbstractByteRange
{
27 public SimpleByteRange() {
30 public SimpleByteRange(int capacity
) {
31 this(new byte[capacity
]);
35 * Create a new {@code ByteRange} over the provided {@code bytes}.
36 * @param bytes The array to wrap.
38 public SimpleByteRange(byte[] bytes
) {
43 * Create a new {@code ByteRange} over the provided {@code bytes}.
44 * @param bytes The array to wrap.
45 * @param offset The offset into {@code bytes} considered the beginning
47 * @param length The length of this range.
49 public SimpleByteRange(byte[] bytes
, int offset
, int length
) {
50 set(bytes
, offset
, length
);
54 // methods for managing the backing array and range viewport
58 public ByteRange
unset() {
59 throw new ReadOnlyByteRangeException();
63 public ByteRange
set(int capacity
) {
64 if (super.bytes
!= null) {
65 throw new ReadOnlyByteRangeException();
67 return super.set(capacity
);
71 public ByteRange
set(byte[] bytes
) {
72 if (super.bytes
!= null) {
73 throw new ReadOnlyByteRangeException();
75 return super.set(bytes
);
79 public ByteRange
set(byte[] bytes
, int offset
, int length
) {
80 if (super.bytes
!= null) {
81 throw new ReadOnlyByteRangeException();
83 return super.set(bytes
, offset
, length
);
87 // methods for retrieving data
90 public ByteRange
put(int index
, byte val
) {
91 throw new ReadOnlyByteRangeException();
95 public ByteRange
put(int index
, byte[] val
) {
96 throw new ReadOnlyByteRangeException();
100 public ByteRange
put(int index
, byte[] val
, int offset
, int length
) {
101 throw new ReadOnlyByteRangeException();
105 // methods for duplicating the current instance
109 public ByteRange
shallowCopy() {
110 SimpleByteRange clone
= new SimpleByteRange(bytes
, offset
, length
);
111 if (isHashCached()) {
118 public ByteRange
shallowCopySubRange(int innerOffset
, int copyLength
) {
119 SimpleByteRange clone
= new SimpleByteRange(bytes
, offset
+ innerOffset
,
121 if (isHashCached()) {
128 public boolean equals(Object thatObject
) {
129 if (thatObject
== null){
132 if (this == thatObject
) {
135 if (hashCode() != thatObject
.hashCode()) {
138 if (!(thatObject
instanceof SimpleByteRange
)) {
141 SimpleByteRange that
= (SimpleByteRange
) thatObject
;
142 return Bytes
.equals(bytes
, offset
, length
, that
.bytes
, that
.offset
, that
.length
);
146 public ByteRange
deepCopy() {
147 SimpleByteRange clone
= new SimpleByteRange(deepCopyToNewArray());
148 if (isHashCached()) {
155 public ByteRange
putInt(int index
, int val
) {
156 throw new ReadOnlyByteRangeException();
160 public ByteRange
putLong(int index
, long val
) {
161 throw new ReadOnlyByteRangeException();
165 public ByteRange
putShort(int index
, short val
) {
166 throw new ReadOnlyByteRangeException();
170 public int putVLong(int index
, long val
) {
171 throw new ReadOnlyByteRangeException();