]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/memory/memory-netty/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / memory / memory-netty / src / main / java / io / netty / buffer / MutableWrappedByteBuf.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package io.netty.buffer;
19
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.nio.ByteBuffer;
24 import java.nio.ByteOrder;
25 import java.nio.channels.FileChannel;
26 import java.nio.channels.GatheringByteChannel;
27 import java.nio.channels.ScatteringByteChannel;
28
29 import io.netty.util.ByteProcessor;
30
31 /**
32 * This is basically a complete copy of netty's DuplicatedByteBuf. We copy because we want to override
33 * some behaviors and make buffer mutable.
34 */
35 abstract class MutableWrappedByteBuf extends AbstractByteBuf {
36
37 ByteBuf buffer;
38
39 public MutableWrappedByteBuf(ByteBuf buffer) {
40 super(buffer.maxCapacity());
41
42 if (buffer instanceof MutableWrappedByteBuf) {
43 this.buffer = ((MutableWrappedByteBuf) buffer).buffer;
44 } else {
45 this.buffer = buffer;
46 }
47
48 setIndex(buffer.readerIndex(), buffer.writerIndex());
49 }
50
51 @Override
52 public ByteBuffer nioBuffer(int index, int length) {
53 return unwrap().nioBuffer(index, length);
54 }
55
56 @Override
57 public ByteBuf unwrap() {
58 return buffer;
59 }
60
61 @Override
62 public ByteBufAllocator alloc() {
63 return buffer.alloc();
64 }
65
66 @Override
67 public ByteOrder order() {
68 return buffer.order();
69 }
70
71 @Override
72 public boolean isDirect() {
73 return buffer.isDirect();
74 }
75
76 @Override
77 public int capacity() {
78 return buffer.capacity();
79 }
80
81 @Override
82 public ByteBuf capacity(int newCapacity) {
83 buffer.capacity(newCapacity);
84 return this;
85 }
86
87 @Override
88 public boolean hasArray() {
89 return buffer.hasArray();
90 }
91
92 @Override
93 public byte[] array() {
94 return buffer.array();
95 }
96
97 @Override
98 public int arrayOffset() {
99 return buffer.arrayOffset();
100 }
101
102 @Override
103 public boolean hasMemoryAddress() {
104 return buffer.hasMemoryAddress();
105 }
106
107 @Override
108 public long memoryAddress() {
109 return buffer.memoryAddress();
110 }
111
112 @Override
113 public byte getByte(int index) {
114 return _getByte(index);
115 }
116
117 @Override
118 protected byte _getByte(int index) {
119 return buffer.getByte(index);
120 }
121
122 @Override
123 public short getShort(int index) {
124 return _getShort(index);
125 }
126
127 @Override
128 protected short _getShort(int index) {
129 return buffer.getShort(index);
130 }
131
132 @Override
133 public short getShortLE(int index) {
134 return buffer.getShortLE(index);
135 }
136
137 @Override
138 protected short _getShortLE(int index) {
139 return buffer.getShortLE(index);
140 }
141
142 @Override
143 public int getUnsignedMedium(int index) {
144 return _getUnsignedMedium(index);
145 }
146
147 @Override
148 protected int _getUnsignedMedium(int index) {
149 return buffer.getUnsignedMedium(index);
150 }
151
152 @Override
153 public int getUnsignedMediumLE(int index) {
154 return buffer.getUnsignedMediumLE(index);
155 }
156
157 @Override
158 protected int _getUnsignedMediumLE(int index) {
159 return buffer.getUnsignedMediumLE(index);
160 }
161
162 @Override
163 public int getInt(int index) {
164 return _getInt(index);
165 }
166
167 @Override
168 protected int _getInt(int index) {
169 return buffer.getInt(index);
170 }
171
172 @Override
173 public int getIntLE(int index) {
174 return buffer.getIntLE(index);
175 }
176
177 @Override
178 protected int _getIntLE(int index) {
179 return buffer.getIntLE(index);
180 }
181
182 @Override
183 public long getLong(int index) {
184 return _getLong(index);
185 }
186
187 @Override
188 protected long _getLong(int index) {
189 return buffer.getLong(index);
190 }
191
192 @Override
193 public long getLongLE(int index) {
194 return buffer.getLongLE(index);
195 }
196
197 @Override
198 protected long _getLongLE(int index) {
199 return buffer.getLongLE(index);
200 }
201
202 @Override
203 public abstract ByteBuf copy(int index, int length);
204
205 @Override
206 public ByteBuf slice(int index, int length) {
207 return new SlicedByteBuf(this, index, length);
208 }
209
210 @Override
211 public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
212 buffer.getBytes(index, dst, dstIndex, length);
213 return this;
214 }
215
216 @Override
217 public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
218 buffer.getBytes(index, dst, dstIndex, length);
219 return this;
220 }
221
222 @Override
223 public ByteBuf getBytes(int index, ByteBuffer dst) {
224 buffer.getBytes(index, dst);
225 return this;
226 }
227
228 @Override
229 public ByteBuf setByte(int index, int value) {
230 _setByte(index, value);
231 return this;
232 }
233
234 @Override
235 protected void _setByte(int index, int value) {
236 buffer.setByte(index, value);
237 }
238
239 @Override
240 public ByteBuf setShort(int index, int value) {
241 _setShort(index, value);
242 return this;
243 }
244
245 @Override
246 protected void _setShort(int index, int value) {
247 buffer.setShort(index, value);
248 }
249
250 @Override
251 public ByteBuf setShortLE(int index, int value) {
252 buffer.setShortLE(index, value);
253 return this;
254 }
255
256 @Override
257 protected void _setShortLE(int index, int value) {
258 buffer.setShortLE(index, value);
259 }
260
261 @Override
262 public ByteBuf setMedium(int index, int value) {
263 _setMedium(index, value);
264 return this;
265 }
266
267 @Override
268 protected void _setMedium(int index, int value) {
269 buffer.setMedium(index, value);
270 }
271
272 @Override
273 public ByteBuf setMediumLE(int index, int value) {
274 buffer.setMediumLE(index, value);
275 return this;
276 }
277
278 @Override
279 protected void _setMediumLE(int index, int value) {
280 buffer.setMediumLE(index, value);
281 }
282
283 @Override
284 public ByteBuf setInt(int index, int value) {
285 _setInt(index, value);
286 return this;
287 }
288
289 @Override
290 protected void _setInt(int index, int value) {
291 buffer.setInt(index, value);
292 }
293
294 @Override
295 public ByteBuf setIntLE(int index, int value) {
296 buffer.setIntLE(index, value);
297 return this;
298 }
299
300 @Override
301 protected void _setIntLE(int index, int value) {
302 buffer.setIntLE(index, value);
303 }
304
305 @Override
306 public ByteBuf setLong(int index, long value) {
307 _setLong(index, value);
308 return this;
309 }
310
311 @Override
312 protected void _setLong(int index, long value) {
313 buffer.setLong(index, value);
314 }
315
316 @Override
317 public ByteBuf setLongLE(int index, long value) {
318 buffer.setLongLE(index, value);
319 return this;
320 }
321
322 @Override
323 protected void _setLongLE(int index, long value) {
324 buffer.setLongLE(index, value);
325 }
326
327 @Override
328 public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
329 buffer.setBytes(index, src, srcIndex, length);
330 return this;
331 }
332
333 @Override
334 public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
335 buffer.setBytes(index, src, srcIndex, length);
336 return this;
337 }
338
339 @Override
340 public ByteBuf setBytes(int index, ByteBuffer src) {
341 buffer.setBytes(index, src);
342 return this;
343 }
344
345 @Override
346 public int setBytes(int index, FileChannel in, long position, int length)
347 throws IOException {
348 return buffer.setBytes(index, in, position, length);
349 }
350
351 @Override
352 public ByteBuf getBytes(int index, OutputStream out, int length)
353 throws IOException {
354 buffer.getBytes(index, out, length);
355 return this;
356 }
357
358 @Override
359 public int getBytes(int index, GatheringByteChannel out, int length)
360 throws IOException {
361 return buffer.getBytes(index, out, length);
362 }
363
364 @Override
365 public int setBytes(int index, InputStream in, int length)
366 throws IOException {
367 return buffer.setBytes(index, in, length);
368 }
369
370 @Override
371 public int setBytes(int index, ScatteringByteChannel in, int length)
372 throws IOException {
373 return buffer.setBytes(index, in, length);
374 }
375
376
377 @Override
378 public int getBytes(int index, FileChannel out, long position, int length)
379 throws IOException {
380 return buffer.getBytes(index, out, position, length);
381 }
382
383 @Override
384 public int nioBufferCount() {
385 return buffer.nioBufferCount();
386 }
387
388 @Override
389 public ByteBuffer[] nioBuffers(int index, int length) {
390 return buffer.nioBuffers(index, length);
391 }
392
393 @Override
394 public ByteBuffer internalNioBuffer(int index, int length) {
395 return nioBuffer(index, length);
396 }
397
398 @Override
399 public int forEachByte(int index, int length, ByteProcessor processor) {
400 return buffer.forEachByte(index, length, processor);
401 }
402
403 @Override
404 public int forEachByteDesc(int index, int length, ByteProcessor processor) {
405 return buffer.forEachByteDesc(index, length, processor);
406 }
407
408 @Override
409 public final int refCnt() {
410 return unwrap().refCnt();
411 }
412
413 @Override
414 public final ByteBuf touch() {
415 unwrap().touch();
416 return this;
417 }
418
419 @Override
420 public final ByteBuf touch(Object hint) {
421 unwrap().touch(hint);
422 return this;
423 }
424
425 @Override
426 public final ByteBuf retain() {
427 unwrap().retain();
428 return this;
429 }
430
431 @Override
432 public final ByteBuf retain(int increment) {
433 unwrap().retain(increment);
434 return this;
435 }
436
437 @Override
438 public boolean release() {
439 return release(1);
440 }
441
442 @Override
443 public boolean release(int decrement) {
444 boolean released = unwrap().release(decrement);
445 return released;
446 }
447
448 }