2008-08-08 02:37:18 +02:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
2008-08-08 02:37:18 +02:00
|
|
|
*
|
2011-12-09 06:18:34 +01:00
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
2008-08-08 02:37:18 +02:00
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-08-08 03:27:24 +02:00
|
|
|
*
|
2009-08-28 09:15:49 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 06:18:34 +01:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2009-08-28 09:15:49 +02:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-08-08 02:37:18 +02:00
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.buffer;
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2013-03-06 10:22:16 +01:00
|
|
|
import io.netty.util.internal.PlatformDependent;
|
|
|
|
|
2008-08-08 02:37:18 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.nio.ByteBuffer;
|
2012-06-11 13:24:44 +02:00
|
|
|
import java.nio.ByteOrder;
|
2008-11-16 14:52:47 +01:00
|
|
|
import java.nio.channels.ClosedChannelException;
|
2016-02-05 04:02:40 +01:00
|
|
|
import java.nio.channels.FileChannel;
|
2008-08-08 02:37:18 +02:00
|
|
|
import java.nio.channels.GatheringByteChannel;
|
|
|
|
import java.nio.channels.ScatteringByteChannel;
|
|
|
|
|
|
|
|
/**
|
2012-06-11 13:24:44 +02:00
|
|
|
* Big endian Java heap buffer implementation.
|
2008-08-08 02:37:18 +02:00
|
|
|
*/
|
2013-04-04 10:26:14 +02:00
|
|
|
public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2012-11-15 22:04:37 +01:00
|
|
|
private final ByteBufAllocator alloc;
|
2015-10-09 21:03:03 +02:00
|
|
|
byte[] array;
|
2012-11-15 22:04:37 +01:00
|
|
|
private ByteBuffer tmpNioBuf;
|
2012-05-25 15:10:10 +02:00
|
|
|
|
2008-09-02 09:13:20 +02:00
|
|
|
/**
|
|
|
|
* Creates a new heap buffer with a newly allocated byte array.
|
|
|
|
*
|
2012-07-19 13:23:55 +02:00
|
|
|
* @param initialCapacity the initial capacity of the underlying byte array
|
|
|
|
* @param maxCapacity the max capacity of the underlying byte array
|
2008-09-02 09:13:20 +02:00
|
|
|
*/
|
2013-04-04 10:26:14 +02:00
|
|
|
protected UnpooledHeapByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) {
|
2012-11-15 22:04:37 +01:00
|
|
|
this(alloc, new byte[initialCapacity], 0, 0, maxCapacity);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2008-09-02 09:13:20 +02:00
|
|
|
/**
|
|
|
|
* Creates a new heap buffer with an existing byte array.
|
|
|
|
*
|
2012-07-19 13:23:55 +02:00
|
|
|
* @param initialArray the initial underlying byte array
|
|
|
|
* @param maxCapacity the max capacity of the underlying byte array
|
2008-09-02 09:13:20 +02:00
|
|
|
*/
|
2013-04-04 10:26:14 +02:00
|
|
|
protected UnpooledHeapByteBuf(ByteBufAllocator alloc, byte[] initialArray, int maxCapacity) {
|
2012-11-15 22:04:37 +01:00
|
|
|
this(alloc, initialArray, 0, initialArray.length, maxCapacity);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-11-15 22:04:37 +01:00
|
|
|
private UnpooledHeapByteBuf(
|
|
|
|
ByteBufAllocator alloc, byte[] initialArray, int readerIndex, int writerIndex, int maxCapacity) {
|
|
|
|
|
|
|
|
super(maxCapacity);
|
|
|
|
|
|
|
|
if (alloc == null) {
|
|
|
|
throw new NullPointerException("alloc");
|
|
|
|
}
|
2012-07-19 13:23:55 +02:00
|
|
|
if (initialArray == null) {
|
|
|
|
throw new NullPointerException("initialArray");
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
2012-07-19 13:23:55 +02:00
|
|
|
if (initialArray.length > maxCapacity) {
|
|
|
|
throw new IllegalArgumentException(String.format(
|
|
|
|
"initialCapacity(%d) > maxCapacity(%d)", initialArray.length, maxCapacity));
|
|
|
|
}
|
|
|
|
|
2012-11-15 22:04:37 +01:00
|
|
|
this.alloc = alloc;
|
2012-07-19 13:23:55 +02:00
|
|
|
setArray(initialArray);
|
2008-08-08 02:37:18 +02:00
|
|
|
setIndex(readerIndex, writerIndex);
|
2012-07-19 13:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setArray(byte[] initialArray) {
|
|
|
|
array = initialArray;
|
2012-11-15 22:04:37 +01:00
|
|
|
tmpNioBuf = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBufAllocator alloc() {
|
|
|
|
return alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteOrder order() {
|
|
|
|
return ByteOrder.BIG_ENDIAN;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2010-01-27 06:07:32 +01:00
|
|
|
public boolean isDirect() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2008-08-08 02:37:18 +02:00
|
|
|
public int capacity() {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2008-08-08 02:37:18 +02:00
|
|
|
return array.length;
|
|
|
|
}
|
|
|
|
|
2012-07-19 13:23:55 +02:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf capacity(int newCapacity) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2012-07-19 13:23:55 +02:00
|
|
|
if (newCapacity < 0 || newCapacity > maxCapacity()) {
|
|
|
|
throw new IllegalArgumentException("newCapacity: " + newCapacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
int oldCapacity = array.length;
|
|
|
|
if (newCapacity > oldCapacity) {
|
|
|
|
byte[] newArray = new byte[newCapacity];
|
2013-11-04 15:18:21 +01:00
|
|
|
System.arraycopy(array, 0, newArray, 0, array.length);
|
2012-07-19 13:23:55 +02:00
|
|
|
setArray(newArray);
|
|
|
|
} else if (newCapacity < oldCapacity) {
|
|
|
|
byte[] newArray = new byte[newCapacity];
|
|
|
|
int readerIndex = readerIndex();
|
|
|
|
if (readerIndex < newCapacity) {
|
|
|
|
int writerIndex = writerIndex();
|
|
|
|
if (writerIndex > newCapacity) {
|
|
|
|
writerIndex(writerIndex = newCapacity);
|
|
|
|
}
|
|
|
|
System.arraycopy(array, readerIndex, newArray, readerIndex, writerIndex - readerIndex);
|
2012-07-20 06:18:17 +02:00
|
|
|
} else {
|
|
|
|
setIndex(newCapacity, newCapacity);
|
2012-07-19 13:23:55 +02:00
|
|
|
}
|
|
|
|
setArray(newArray);
|
|
|
|
}
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2012-07-19 13:23:55 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2009-11-25 08:08:52 +01:00
|
|
|
public boolean hasArray() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2009-11-25 08:08:52 +01:00
|
|
|
public byte[] array() {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2009-11-25 08:08:52 +01:00
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2009-11-25 08:08:52 +01:00
|
|
|
public int arrayOffset() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-06 10:22:16 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasMemoryAddress() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long memoryAddress() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
|
2013-03-06 10:22:16 +01:00
|
|
|
checkDstIndex(index, length, dstIndex, dst.capacity());
|
|
|
|
if (dst.hasMemoryAddress()) {
|
|
|
|
PlatformDependent.copyMemory(array, index, dst.memoryAddress() + dstIndex, length);
|
|
|
|
} else if (dst.hasArray()) {
|
2012-12-05 22:11:48 +01:00
|
|
|
getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length);
|
2008-08-08 02:37:18 +02:00
|
|
|
} else {
|
|
|
|
dst.setBytes(dstIndex, array, index, length);
|
|
|
|
}
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
|
2013-03-06 10:22:16 +01:00
|
|
|
checkDstIndex(index, length, dstIndex, dst.length);
|
2008-08-08 02:37:18 +02:00
|
|
|
System.arraycopy(array, index, dst, dstIndex, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf getBytes(int index, ByteBuffer dst) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2008-08-08 02:37:18 +02:00
|
|
|
dst.put(array, index, Math.min(capacity() - index, dst.remaining()));
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2008-08-08 02:37:18 +02:00
|
|
|
out.write(array, index, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-09-20 16:24:46 +02:00
|
|
|
return getBytes(index, out, length, false);
|
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int getBytes(int index, FileChannel out, long position, int length) throws IOException {
|
|
|
|
ensureAccessible();
|
|
|
|
return getBytes(index, out, position, length, false);
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:24:46 +02:00
|
|
|
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
|
|
|
|
ensureAccessible();
|
|
|
|
ByteBuffer tmpBuf;
|
|
|
|
if (internal) {
|
|
|
|
tmpBuf = internalNioBuffer();
|
|
|
|
} else {
|
|
|
|
tmpBuf = ByteBuffer.wrap(array);
|
|
|
|
}
|
|
|
|
return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length));
|
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
private int getBytes(int index, FileChannel out, long position, int length, boolean internal) throws IOException {
|
|
|
|
ensureAccessible();
|
|
|
|
ByteBuffer tmpBuf = internal ? internalNioBuffer() : ByteBuffer.wrap(array);
|
|
|
|
return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length), position);
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:24:46 +02:00
|
|
|
@Override
|
|
|
|
public int readBytes(GatheringByteChannel out, int length) throws IOException {
|
|
|
|
checkReadableBytes(length);
|
|
|
|
int readBytes = getBytes(readerIndex, out, length, true);
|
|
|
|
readerIndex += readBytes;
|
|
|
|
return readBytes;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int readBytes(FileChannel out, long position, int length) throws IOException {
|
|
|
|
checkReadableBytes(length);
|
|
|
|
int readBytes = getBytes(readerIndex, out, position, length, true);
|
|
|
|
readerIndex += readBytes;
|
|
|
|
return readBytes;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
2013-03-06 10:22:16 +01:00
|
|
|
checkSrcIndex(index, length, srcIndex, src.capacity());
|
|
|
|
if (src.hasMemoryAddress()) {
|
|
|
|
PlatformDependent.copyMemory(src.memoryAddress() + srcIndex, array, index, length);
|
|
|
|
} else if (src.hasArray()) {
|
2012-12-05 22:11:48 +01:00
|
|
|
setBytes(index, src.array(), src.arrayOffset() + srcIndex, length);
|
2008-08-08 02:37:18 +02:00
|
|
|
} else {
|
|
|
|
src.getBytes(srcIndex, array, index, length);
|
|
|
|
}
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
|
2013-03-06 10:22:16 +01:00
|
|
|
checkSrcIndex(index, length, srcIndex, src.length);
|
2008-08-08 02:37:18 +02:00
|
|
|
System.arraycopy(src, srcIndex, array, index, length);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf setBytes(int index, ByteBuffer src) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2008-08-08 02:37:18 +02:00
|
|
|
src.get(array, index, src.remaining());
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2008-08-20 05:09:23 +02:00
|
|
|
public int setBytes(int index, InputStream in, int length) throws IOException {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2012-05-25 22:58:56 +02:00
|
|
|
return in.read(array, index, length);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2008-08-08 02:37:18 +02:00
|
|
|
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2012-05-25 15:10:10 +02:00
|
|
|
try {
|
2012-11-15 22:04:37 +01:00
|
|
|
return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length));
|
2014-07-02 12:04:11 +02:00
|
|
|
} catch (ClosedChannelException ignored) {
|
2012-05-25 15:10:10 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int setBytes(int index, FileChannel in, long position, int length) throws IOException {
|
|
|
|
ensureAccessible();
|
|
|
|
try {
|
|
|
|
return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length), position);
|
|
|
|
} catch (ClosedChannelException ignored) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-12-14 04:20:33 +01:00
|
|
|
public int nioBufferCount() {
|
|
|
|
return 1;
|
2012-06-02 10:30:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuffer nioBuffer(int index, int length) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-10-16 10:34:33 +02:00
|
|
|
return ByteBuffer.wrap(array, index, length).slice();
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2012-08-13 02:29:07 +02:00
|
|
|
@Override
|
2012-12-05 22:11:48 +01:00
|
|
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
2012-12-14 04:20:33 +01:00
|
|
|
return new ByteBuffer[] { nioBuffer(index, length) };
|
2012-08-13 02:29:07 +02:00
|
|
|
}
|
|
|
|
|
2013-06-13 05:40:26 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuffer internalNioBuffer(int index, int length) {
|
2014-06-30 07:10:12 +02:00
|
|
|
checkIndex(index, length);
|
2013-06-13 05:40:26 +02:00
|
|
|
return (ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length);
|
|
|
|
}
|
|
|
|
|
2013-03-06 02:32:29 +01:00
|
|
|
@Override
|
|
|
|
public byte getByte(int index) {
|
|
|
|
ensureAccessible();
|
|
|
|
return _getByte(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected byte _getByte(int index) {
|
2015-10-21 11:24:18 +02:00
|
|
|
return HeapByteBufUtil.getByte(array, index);
|
2013-03-06 02:32:29 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public short getShort(int index) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
return _getShort(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected short _getShort(int index) {
|
2015-10-21 11:24:18 +02:00
|
|
|
return HeapByteBufUtil.getShort(array, index);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected short _getShortLE(int index) {
|
|
|
|
return HeapByteBufUtil.getShortLE(array, index);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public int getUnsignedMedium(int index) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
return _getUnsignedMedium(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int _getUnsignedMedium(int index) {
|
2015-10-21 11:24:18 +02:00
|
|
|
return HeapByteBufUtil.getUnsignedMedium(array, index);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected int _getUnsignedMediumLE(int index) {
|
|
|
|
return HeapByteBufUtil.getUnsignedMediumLE(array, index);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public int getInt(int index) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
return _getInt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int _getInt(int index) {
|
2015-10-21 11:24:18 +02:00
|
|
|
return HeapByteBufUtil.getInt(array, index);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected int _getIntLE(int index) {
|
|
|
|
return HeapByteBufUtil.getIntLE(array, index);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public long getLong(int index) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
return _getLong(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected long _getLong(int index) {
|
2015-10-21 11:24:18 +02:00
|
|
|
return HeapByteBufUtil.getLong(array, index);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected long _getLongLE(int index) {
|
|
|
|
return HeapByteBufUtil.getLongLE(array, index);
|
|
|
|
}
|
|
|
|
|
2013-03-06 02:32:29 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf setByte(int index, int value) {
|
|
|
|
ensureAccessible();
|
|
|
|
_setByte(index, value);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void _setByte(int index, int value) {
|
2015-10-21 11:24:18 +02:00
|
|
|
HeapByteBufUtil.setByte(array, index, value);
|
2013-03-06 02:32:29 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf setShort(int index, int value) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
_setShort(index, value);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void _setShort(int index, int value) {
|
2015-10-21 11:24:18 +02:00
|
|
|
HeapByteBufUtil.setShort(array, index, value);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setShortLE(int index, int value) {
|
|
|
|
HeapByteBufUtil.setShortLE(array, index, value);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf setMedium(int index, int value) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
_setMedium(index, value);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void _setMedium(int index, int value) {
|
2015-10-21 11:24:18 +02:00
|
|
|
HeapByteBufUtil.setMedium(array, index, value);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setMediumLE(int index, int value) {
|
|
|
|
HeapByteBufUtil.setMediumLE(array, index, value);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf setInt(int index, int value) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
_setInt(index, value);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void _setInt(int index, int value) {
|
2015-10-21 11:24:18 +02:00
|
|
|
HeapByteBufUtil.setInt(array, index, value);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setIntLE(int index, int value) {
|
|
|
|
HeapByteBufUtil.setIntLE(array, index, value);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
2012-10-18 08:57:23 +02:00
|
|
|
public ByteBuf setLong(int index, long value) {
|
2013-02-10 05:10:09 +01:00
|
|
|
ensureAccessible();
|
2013-03-06 02:32:29 +01:00
|
|
|
_setLong(index, value);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void _setLong(int index, long value) {
|
2015-10-21 11:24:18 +02:00
|
|
|
HeapByteBufUtil.setLong(array, index, value);
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setLongLE(int index, long value) {
|
|
|
|
HeapByteBufUtil.setLongLE(array, index, value);
|
|
|
|
}
|
|
|
|
|
2012-06-11 13:24:44 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuf copy(int index, int length) {
|
2013-01-18 05:10:54 +01:00
|
|
|
checkIndex(index, length);
|
2012-06-11 13:24:44 +02:00
|
|
|
byte[] copiedArray = new byte[length];
|
|
|
|
System.arraycopy(array, index, copiedArray, 0, length);
|
2012-11-15 22:04:37 +01:00
|
|
|
return new UnpooledHeapByteBuf(alloc(), copiedArray, maxCapacity());
|
2012-07-19 13:23:55 +02:00
|
|
|
}
|
|
|
|
|
2012-12-17 09:41:21 +01:00
|
|
|
private ByteBuffer internalNioBuffer() {
|
2012-11-15 22:04:37 +01:00
|
|
|
ByteBuffer tmpNioBuf = this.tmpNioBuf;
|
|
|
|
if (tmpNioBuf == null) {
|
|
|
|
this.tmpNioBuf = tmpNioBuf = ByteBuffer.wrap(array);
|
2012-07-19 13:23:55 +02:00
|
|
|
}
|
2012-11-15 22:04:37 +01:00
|
|
|
return tmpNioBuf;
|
|
|
|
}
|
2012-08-13 02:29:07 +02:00
|
|
|
|
2012-12-02 12:17:53 +01:00
|
|
|
@Override
|
2013-02-10 05:10:09 +01:00
|
|
|
protected void deallocate() {
|
2012-12-17 10:27:30 +01:00
|
|
|
array = null;
|
2012-11-15 22:04:37 +01:00
|
|
|
}
|
2012-07-20 05:33:17 +02:00
|
|
|
|
2012-11-15 22:04:37 +01:00
|
|
|
@Override
|
|
|
|
public ByteBuf unwrap() {
|
|
|
|
return null;
|
2012-06-11 13:24:44 +02:00
|
|
|
}
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|