]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/memory/memory-netty/src/main/java/io/netty/buffer/MutableWrappedByteBuf.java
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package io
.netty
.buffer
;
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
;
29 import io
.netty
.util
.ByteProcessor
;
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.
35 abstract class MutableWrappedByteBuf
extends AbstractByteBuf
{
39 public MutableWrappedByteBuf(ByteBuf buffer
) {
40 super(buffer
.maxCapacity());
42 if (buffer
instanceof MutableWrappedByteBuf
) {
43 this.buffer
= ((MutableWrappedByteBuf
) buffer
).buffer
;
48 setIndex(buffer
.readerIndex(), buffer
.writerIndex());
52 public ByteBuffer
nioBuffer(int index
, int length
) {
53 return unwrap().nioBuffer(index
, length
);
57 public ByteBuf
unwrap() {
62 public ByteBufAllocator
alloc() {
63 return buffer
.alloc();
67 public ByteOrder
order() {
68 return buffer
.order();
72 public boolean isDirect() {
73 return buffer
.isDirect();
77 public int capacity() {
78 return buffer
.capacity();
82 public ByteBuf
capacity(int newCapacity
) {
83 buffer
.capacity(newCapacity
);
88 public boolean hasArray() {
89 return buffer
.hasArray();
93 public byte[] array() {
94 return buffer
.array();
98 public int arrayOffset() {
99 return buffer
.arrayOffset();
103 public boolean hasMemoryAddress() {
104 return buffer
.hasMemoryAddress();
108 public long memoryAddress() {
109 return buffer
.memoryAddress();
113 public byte getByte(int index
) {
114 return _getByte(index
);
118 protected byte _getByte(int index
) {
119 return buffer
.getByte(index
);
123 public short getShort(int index
) {
124 return _getShort(index
);
128 protected short _getShort(int index
) {
129 return buffer
.getShort(index
);
133 public short getShortLE(int index
) {
134 return buffer
.getShortLE(index
);
138 protected short _getShortLE(int index
) {
139 return buffer
.getShortLE(index
);
143 public int getUnsignedMedium(int index
) {
144 return _getUnsignedMedium(index
);
148 protected int _getUnsignedMedium(int index
) {
149 return buffer
.getUnsignedMedium(index
);
153 public int getUnsignedMediumLE(int index
) {
154 return buffer
.getUnsignedMediumLE(index
);
158 protected int _getUnsignedMediumLE(int index
) {
159 return buffer
.getUnsignedMediumLE(index
);
163 public int getInt(int index
) {
164 return _getInt(index
);
168 protected int _getInt(int index
) {
169 return buffer
.getInt(index
);
173 public int getIntLE(int index
) {
174 return buffer
.getIntLE(index
);
178 protected int _getIntLE(int index
) {
179 return buffer
.getIntLE(index
);
183 public long getLong(int index
) {
184 return _getLong(index
);
188 protected long _getLong(int index
) {
189 return buffer
.getLong(index
);
193 public long getLongLE(int index
) {
194 return buffer
.getLongLE(index
);
198 protected long _getLongLE(int index
) {
199 return buffer
.getLongLE(index
);
203 public abstract ByteBuf
copy(int index
, int length
);
206 public ByteBuf
slice(int index
, int length
) {
207 return new SlicedByteBuf(this, index
, length
);
211 public ByteBuf
getBytes(int index
, ByteBuf dst
, int dstIndex
, int length
) {
212 buffer
.getBytes(index
, dst
, dstIndex
, length
);
217 public ByteBuf
getBytes(int index
, byte[] dst
, int dstIndex
, int length
) {
218 buffer
.getBytes(index
, dst
, dstIndex
, length
);
223 public ByteBuf
getBytes(int index
, ByteBuffer dst
) {
224 buffer
.getBytes(index
, dst
);
229 public ByteBuf
setByte(int index
, int value
) {
230 _setByte(index
, value
);
235 protected void _setByte(int index
, int value
) {
236 buffer
.setByte(index
, value
);
240 public ByteBuf
setShort(int index
, int value
) {
241 _setShort(index
, value
);
246 protected void _setShort(int index
, int value
) {
247 buffer
.setShort(index
, value
);
251 public ByteBuf
setShortLE(int index
, int value
) {
252 buffer
.setShortLE(index
, value
);
257 protected void _setShortLE(int index
, int value
) {
258 buffer
.setShortLE(index
, value
);
262 public ByteBuf
setMedium(int index
, int value
) {
263 _setMedium(index
, value
);
268 protected void _setMedium(int index
, int value
) {
269 buffer
.setMedium(index
, value
);
273 public ByteBuf
setMediumLE(int index
, int value
) {
274 buffer
.setMediumLE(index
, value
);
279 protected void _setMediumLE(int index
, int value
) {
280 buffer
.setMediumLE(index
, value
);
284 public ByteBuf
setInt(int index
, int value
) {
285 _setInt(index
, value
);
290 protected void _setInt(int index
, int value
) {
291 buffer
.setInt(index
, value
);
295 public ByteBuf
setIntLE(int index
, int value
) {
296 buffer
.setIntLE(index
, value
);
301 protected void _setIntLE(int index
, int value
) {
302 buffer
.setIntLE(index
, value
);
306 public ByteBuf
setLong(int index
, long value
) {
307 _setLong(index
, value
);
312 protected void _setLong(int index
, long value
) {
313 buffer
.setLong(index
, value
);
317 public ByteBuf
setLongLE(int index
, long value
) {
318 buffer
.setLongLE(index
, value
);
323 protected void _setLongLE(int index
, long value
) {
324 buffer
.setLongLE(index
, value
);
328 public ByteBuf
setBytes(int index
, byte[] src
, int srcIndex
, int length
) {
329 buffer
.setBytes(index
, src
, srcIndex
, length
);
334 public ByteBuf
setBytes(int index
, ByteBuf src
, int srcIndex
, int length
) {
335 buffer
.setBytes(index
, src
, srcIndex
, length
);
340 public ByteBuf
setBytes(int index
, ByteBuffer src
) {
341 buffer
.setBytes(index
, src
);
346 public int setBytes(int index
, FileChannel in
, long position
, int length
)
348 return buffer
.setBytes(index
, in
, position
, length
);
352 public ByteBuf
getBytes(int index
, OutputStream out
, int length
)
354 buffer
.getBytes(index
, out
, length
);
359 public int getBytes(int index
, GatheringByteChannel out
, int length
)
361 return buffer
.getBytes(index
, out
, length
);
365 public int setBytes(int index
, InputStream in
, int length
)
367 return buffer
.setBytes(index
, in
, length
);
371 public int setBytes(int index
, ScatteringByteChannel in
, int length
)
373 return buffer
.setBytes(index
, in
, length
);
378 public int getBytes(int index
, FileChannel out
, long position
, int length
)
380 return buffer
.getBytes(index
, out
, position
, length
);
384 public int nioBufferCount() {
385 return buffer
.nioBufferCount();
389 public ByteBuffer
[] nioBuffers(int index
, int length
) {
390 return buffer
.nioBuffers(index
, length
);
394 public ByteBuffer
internalNioBuffer(int index
, int length
) {
395 return nioBuffer(index
, length
);
399 public int forEachByte(int index
, int length
, ByteProcessor processor
) {
400 return buffer
.forEachByte(index
, length
, processor
);
404 public int forEachByteDesc(int index
, int length
, ByteProcessor processor
) {
405 return buffer
.forEachByteDesc(index
, length
, processor
);
409 public final int refCnt() {
410 return unwrap().refCnt();
414 public final ByteBuf
touch() {
420 public final ByteBuf
touch(Object hint
) {
421 unwrap().touch(hint
);
426 public final ByteBuf
retain() {
432 public final ByteBuf
retain(int increment
) {
433 unwrap().retain(increment
);
438 public boolean release() {
443 public boolean release(int decrement
) {
444 boolean released
= unwrap().release(decrement
);