001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.util; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Extends the basic {@link SimpleMutableByteRange} implementation with position support and it is a 024 * readonly version. {@code position} is considered transient, not fundamental to the definition of 025 * the range, and does not participate in {@link #compareTo(ByteRange)}, {@link #hashCode()}, or 026 * {@link #equals(Object)}. {@code Position} is retained by copy operations. 027 */ 028@InterfaceAudience.Public 029@edu.umd.cs.findbugs.annotations.SuppressWarnings("EQ_DOESNT_OVERRIDE_EQUALS") 030public class SimplePositionedByteRange extends AbstractPositionedByteRange { 031 032 /** 033 * Create a new {@code PositionedByteRange} lacking a backing array and with an undefined 034 * viewport. 035 */ 036 public SimplePositionedByteRange() { 037 super(); 038 } 039 040 /** 041 * Create a new {@code PositionedByteRange} over a new backing array of size {@code capacity}. The 042 * range's offset and length are 0 and {@code capacity}, respectively. 043 * @param capacity the size of the backing array. 044 */ 045 public SimplePositionedByteRange(int capacity) { 046 this(new byte[capacity]); 047 } 048 049 /** 050 * Create a new {@code PositionedByteRange} over the provided {@code bytes}. 051 * @param bytes The array to wrap. 052 */ 053 public SimplePositionedByteRange(byte[] bytes) { 054 set(bytes); 055 } 056 057 /** 058 * Create a new {@code PositionedByteRange} over the provided {@code bytes}. 059 * @param bytes The array to wrap. 060 * @param offset The offset into {@code bytes} considered the beginning of this range. 061 * @param length The length of this range. 062 */ 063 public SimplePositionedByteRange(byte[] bytes, int offset, int length) { 064 set(bytes, offset, length); 065 } 066 067 @Override 068 public PositionedByteRange set(int capacity) { 069 if (super.bytes != null) { 070 throw new ReadOnlyByteRangeException(); 071 } 072 return super.set(capacity); 073 } 074 075 @Override 076 public PositionedByteRange set(byte[] bytes) { 077 if (super.bytes != null) { 078 throw new ReadOnlyByteRangeException(); 079 } 080 return super.set(bytes); 081 } 082 083 @Override 084 public PositionedByteRange set(byte[] bytes, int offset, int length) { 085 if (super.bytes != null) { 086 throw new ReadOnlyByteRangeException(); 087 } 088 return super.set(bytes, offset, length); 089 } 090 091 @Override 092 public PositionedByteRange put(byte val) { 093 throw new ReadOnlyByteRangeException(); 094 } 095 096 @Override 097 public PositionedByteRange putShort(short val) { 098 throw new ReadOnlyByteRangeException(); 099 } 100 101 @Override 102 public PositionedByteRange putInt(int val) { 103 throw new ReadOnlyByteRangeException(); 104 } 105 106 @Override 107 public PositionedByteRange putLong(long val) { 108 throw new ReadOnlyByteRangeException(); 109 } 110 111 @Override 112 public int putVLong(long val) { 113 throw new ReadOnlyByteRangeException(); 114 } 115 116 @Override 117 public PositionedByteRange put(byte[] val) { 118 throw new ReadOnlyByteRangeException(); 119 } 120 121 @Override 122 public PositionedByteRange put(byte[] val, int offset, int length) { 123 throw new ReadOnlyByteRangeException(); 124 } 125 126 @Override 127 public PositionedByteRange get(int index, byte[] dst) { 128 super.get(index, dst); 129 return this; 130 } 131 132 @Override 133 public PositionedByteRange get(int index, byte[] dst, int offset, int length) { 134 super.get(index, dst, offset, length); 135 return this; 136 } 137 138 @Override 139 public PositionedByteRange put(int index, byte val) { 140 throw new ReadOnlyByteRangeException(); 141 } 142 143 @Override 144 public PositionedByteRange putShort(int index, short val) { 145 throw new ReadOnlyByteRangeException(); 146 } 147 148 @Override 149 public PositionedByteRange putInt(int index, int val) { 150 throw new ReadOnlyByteRangeException(); 151 } 152 153 @Override 154 public int putVLong(int index, long val) { 155 throw new ReadOnlyByteRangeException(); 156 } 157 158 @Override 159 public PositionedByteRange putLong(int index, long val) { 160 throw new ReadOnlyByteRangeException(); 161 } 162 163 @Override 164 public PositionedByteRange put(int index, byte[] val) { 165 throw new ReadOnlyByteRangeException(); 166 } 167 168 @Override 169 public PositionedByteRange put(int index, byte[] val, int offset, int length) { 170 throw new ReadOnlyByteRangeException(); 171 } 172 173 @Override 174 public PositionedByteRange deepCopy() { 175 SimplePositionedByteRange clone = new SimplePositionedByteRange(deepCopyToNewArray()); 176 clone.position = this.position; 177 return clone; 178 } 179 180 @Override 181 public PositionedByteRange shallowCopy() { 182 SimplePositionedByteRange clone = new SimplePositionedByteRange(bytes, offset, length); 183 clone.position = this.position; 184 return clone; 185 } 186 187 @Override 188 public PositionedByteRange shallowCopySubRange(int innerOffset, int copyLength) { 189 SimplePositionedByteRange clone = 190 new SimplePositionedByteRange(bytes, offset + innerOffset, copyLength); 191 clone.position = this.position; 192 return clone; 193 } 194 195 @Override 196 public PositionedByteRange setLimit(int limit) { 197 throw new ReadOnlyByteRangeException(); 198 } 199 200 @Override 201 public PositionedByteRange unset() { 202 throw new ReadOnlyByteRangeException(); 203 } 204 205}