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
|
|
|
|
2015-04-01 01:23:52 +02:00
|
|
|
import io.netty.util.ByteProcessor;
|
2016-04-11 11:47:35 +02:00
|
|
|
import io.netty.util.CharsetUtil;
|
2015-04-01 01:23:52 +02:00
|
|
|
|
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-11-15 22:04:37 +01:00
|
|
|
import java.nio.ByteOrder;
|
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;
|
2016-04-11 11:47:35 +02:00
|
|
|
import java.nio.charset.Charset;
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2016-07-26 21:50:56 +02:00
|
|
|
import static io.netty.util.internal.MathUtil.isOutOfBounds;
|
|
|
|
|
2008-08-08 02:37:18 +02:00
|
|
|
/**
|
2008-09-02 09:13:20 +02:00
|
|
|
* A derived buffer which exposes its parent's sub-region only. It is
|
2012-06-10 04:08:43 +02:00
|
|
|
* recommended to use {@link ByteBuf#slice()} and
|
|
|
|
* {@link ByteBuf#slice(int, int)} instead of calling the constructor
|
2008-09-02 09:13:20 +02:00
|
|
|
* explicitly.
|
2016-04-13 13:34:39 +02:00
|
|
|
*
|
|
|
|
* @deprecated Do not use.
|
2008-08-08 02:37:18 +02:00
|
|
|
*/
|
2016-04-13 13:34:39 +02:00
|
|
|
@Deprecated
|
2013-02-10 05:10:09 +01:00
|
|
|
public class SlicedByteBuf extends AbstractDerivedByteBuf {
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2015-08-26 22:24:44 +02:00
|
|
|
private final ByteBuf buffer;
|
|
|
|
private final int adjustment;
|
|
|
|
private final int length;
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2012-12-05 11:28:56 +01:00
|
|
|
public SlicedByteBuf(ByteBuf buffer, int index, int length) {
|
2012-11-15 22:04:37 +01:00
|
|
|
super(length);
|
2016-07-26 21:50:56 +02:00
|
|
|
if (isOutOfBounds(index, length, buffer.capacity())) {
|
2014-07-02 12:04:11 +02:00
|
|
|
throw new IndexOutOfBoundsException(buffer + ".slice(" + index + ", " + length + ')');
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 13:23:55 +02:00
|
|
|
if (buffer instanceof SlicedByteBuf) {
|
|
|
|
this.buffer = ((SlicedByteBuf) buffer).buffer;
|
|
|
|
adjustment = ((SlicedByteBuf) buffer).adjustment + index;
|
|
|
|
} else if (buffer instanceof DuplicatedByteBuf) {
|
2012-12-05 11:28:56 +01:00
|
|
|
this.buffer = buffer.unwrap();
|
2012-07-19 13:23:55 +02:00
|
|
|
adjustment = index;
|
|
|
|
} else {
|
|
|
|
this.buffer = buffer;
|
|
|
|
adjustment = index;
|
|
|
|
}
|
2008-08-08 02:37:18 +02:00
|
|
|
this.length = length;
|
2015-08-26 22:24:44 +02:00
|
|
|
|
|
|
|
writerIndex(length);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 10:31:48 +02:00
|
|
|
final int adjustment() {
|
|
|
|
return adjustment;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-06-10 04:08:43 +02:00
|
|
|
public ByteBuf unwrap() {
|
2008-08-08 02:37:18 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2012-11-15 22:04:37 +01:00
|
|
|
@Override
|
|
|
|
public ByteBufAllocator alloc() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().alloc();
|
2012-11-15 22:04:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-13 13:34:39 +02:00
|
|
|
@Deprecated
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteOrder order() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().order();
|
2012-11-15 22:04:37 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2010-01-27 06:07:32 +01:00
|
|
|
public boolean isDirect() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().isDirect();
|
2010-01-27 06:07:32 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2008-08-08 02:37:18 +02:00
|
|
|
public int capacity() {
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2012-07-19 13:23:55 +02:00
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf capacity(int newCapacity) {
|
2012-07-19 13:23:55 +02:00
|
|
|
throw new UnsupportedOperationException("sliced buffer");
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2009-11-25 08:08:52 +01:00
|
|
|
public boolean hasArray() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().hasArray();
|
2009-11-25 08:08:52 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2009-11-25 08:08:52 +01:00
|
|
|
public byte[] array() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().array();
|
2009-11-25 08:08:52 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2009-11-25 08:08:52 +01:00
|
|
|
public int arrayOffset() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return idx(unwrap().arrayOffset());
|
2009-11-25 08:08:52 +01:00
|
|
|
}
|
|
|
|
|
2013-03-06 10:22:16 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasMemoryAddress() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().hasMemoryAddress();
|
2013-03-06 10:22:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long memoryAddress() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().memoryAddress() + adjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public byte getByte(int index) {
|
|
|
|
checkIndex0(index, 1);
|
|
|
|
return unwrap().getByte(idx(index));
|
2013-03-06 10:22:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected byte _getByte(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getByte(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getShort(int index) {
|
|
|
|
checkIndex0(index, 2);
|
|
|
|
return unwrap().getShort(idx(index));
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected short _getShort(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getShort(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getShortLE(int index) {
|
|
|
|
checkIndex0(index, 2);
|
|
|
|
return unwrap().getShortLE(idx(index));
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected short _getShortLE(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getShortLE(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getUnsignedMedium(int index) {
|
|
|
|
checkIndex0(index, 3);
|
|
|
|
return unwrap().getUnsignedMedium(idx(index));
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected int _getUnsignedMedium(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getUnsignedMedium(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getUnsignedMediumLE(int index) {
|
|
|
|
checkIndex0(index, 3);
|
|
|
|
return unwrap().getUnsignedMediumLE(idx(index));
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected int _getUnsignedMediumLE(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getUnsignedMediumLE(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInt(int index) {
|
|
|
|
checkIndex0(index, 4);
|
|
|
|
return unwrap().getInt(idx(index));
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected int _getInt(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getInt(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getIntLE(int index) {
|
|
|
|
checkIndex0(index, 4);
|
|
|
|
return unwrap().getIntLE(idx(index));
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected int _getIntLE(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getIntLE(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getLong(int index) {
|
|
|
|
checkIndex0(index, 8);
|
|
|
|
return unwrap().getLong(idx(index));
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected long _getLong(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getLong(idx(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getLongLE(int index) {
|
|
|
|
checkIndex0(index, 8);
|
|
|
|
return unwrap().getLongLE(idx(index));
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected long _getLongLE(int index) {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getLongLE(idx(index));
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-06-10 04:08:43 +02:00
|
|
|
public ByteBuf duplicate() {
|
2016-04-13 13:34:39 +02:00
|
|
|
final ByteBuf duplicate = unwrap().slice(adjustment, length);
|
2008-08-26 13:08:55 +02:00
|
|
|
duplicate.setIndex(readerIndex(), writerIndex());
|
|
|
|
return duplicate;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-06-10 04:08:43 +02:00
|
|
|
public ByteBuf copy(int index, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().copy(idx(index), length);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-06-10 04:08:43 +02:00
|
|
|
public ByteBuf slice(int index, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().slice(idx(index), length);
|
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, ByteBuf dst, int dstIndex, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().getBytes(idx(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-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().getBytes(idx(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-11-15 22:04:37 +01:00
|
|
|
public ByteBuf getBytes(int index, ByteBuffer dst) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, dst.remaining());
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().getBytes(idx(index), dst);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setByte(int index, int value) {
|
|
|
|
checkIndex0(index, 1);
|
|
|
|
unwrap().setByte(idx(index), value);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2016-04-11 11:47:35 +02:00
|
|
|
@Override
|
|
|
|
public CharSequence getCharSequence(int index, int length, Charset charset) {
|
|
|
|
checkIndex0(index, length);
|
|
|
|
return buffer.getCharSequence(idx(index), length, charset);
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected void _setByte(int index, int value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setByte(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setShort(int index, int value) {
|
|
|
|
checkIndex0(index, 2);
|
|
|
|
unwrap().setShort(idx(index), value);
|
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected void _setShort(int index, int value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setShort(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setShortLE(int index, int value) {
|
|
|
|
checkIndex0(index, 2);
|
|
|
|
unwrap().setShortLE(idx(index), value);
|
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setShortLE(int index, int value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setShortLE(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setMedium(int index, int value) {
|
|
|
|
checkIndex0(index, 3);
|
|
|
|
unwrap().setMedium(idx(index), value);
|
|
|
|
return this;
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected void _setMedium(int index, int value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setMedium(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setMediumLE(int index, int value) {
|
|
|
|
checkIndex0(index, 3);
|
|
|
|
unwrap().setMediumLE(idx(index), value);
|
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setMediumLE(int index, int value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setMediumLE(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setInt(int index, int value) {
|
|
|
|
checkIndex0(index, 4);
|
|
|
|
unwrap().setInt(idx(index), value);
|
|
|
|
return this;
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected void _setInt(int index, int value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setInt(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setIntLE(int index, int value) {
|
|
|
|
checkIndex0(index, 4);
|
|
|
|
unwrap().setIntLE(idx(index), value);
|
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setIntLE(int index, int value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setIntLE(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setLong(int index, long value) {
|
|
|
|
checkIndex0(index, 8);
|
|
|
|
unwrap().setLong(idx(index), value);
|
|
|
|
return this;
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 02:32:29 +01:00
|
|
|
protected void _setLong(int index, long value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setLong(idx(index), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf setLongLE(int index, long value) {
|
|
|
|
checkIndex0(index, 8);
|
|
|
|
unwrap().setLongLE(idx(index), value);
|
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 22:20:16 +01:00
|
|
|
@Override
|
|
|
|
protected void _setLongLE(int index, long value) {
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setLongLE(idx(index), value);
|
2015-11-16 22:20:16 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-11-15 22:04:37 +01:00
|
|
|
public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setBytes(idx(index), src, srcIndex, 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 ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setBytes(idx(index), src, srcIndex, 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 ByteBuf setBytes(int index, ByteBuffer src) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, src.remaining());
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().setBytes(idx(index), src);
|
2012-10-18 08:57:23 +02:00
|
|
|
return this;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2016-04-11 11:47:35 +02:00
|
|
|
@Override
|
|
|
|
public int setCharSequence(int index, CharSequence sequence, Charset charset) {
|
|
|
|
if (charset.equals(CharsetUtil.UTF_8)) {
|
|
|
|
checkIndex0(index, ByteBufUtil.utf8MaxBytes(sequence));
|
|
|
|
return ByteBufUtil.writeUtf8(this, idx(index), sequence, sequence.length());
|
|
|
|
}
|
|
|
|
if (charset.equals(CharsetUtil.US_ASCII)) {
|
|
|
|
int len = sequence.length();
|
|
|
|
checkIndex0(index, len);
|
|
|
|
return ByteBufUtil.writeAscii(this, idx(index), sequence, len);
|
|
|
|
}
|
|
|
|
byte[] bytes = sequence.toString().getBytes(charset);
|
|
|
|
checkIndex0(index, bytes.length);
|
|
|
|
buffer.setBytes(idx(index), bytes);
|
|
|
|
return bytes.length;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 10:22:16 +01:00
|
|
|
public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
unwrap().getBytes(idx(index), out, 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
|
2013-03-06 10:22:16 +01:00
|
|
|
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getBytes(idx(index), out, length);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2016-02-05 04:02:40 +01:00
|
|
|
@Override
|
|
|
|
public int getBytes(int index, FileChannel out, long position, int length) throws IOException {
|
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().getBytes(idx(index), out, position, length);
|
2016-02-05 04:02:40 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 10:22:16 +01:00
|
|
|
public int setBytes(int index, InputStream in, int length) throws IOException {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().setBytes(idx(index), in, length);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2013-03-06 10:22:16 +01:00
|
|
|
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().setBytes(idx(index), in, length);
|
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 {
|
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().setBytes(idx(index), in, position, length);
|
2016-02-05 04:02:40 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-12-14 04:20:33 +01:00
|
|
|
public int nioBufferCount() {
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().nioBufferCount();
|
2012-06-02 10:30:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuffer nioBuffer(int index, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().nioBuffer(idx(index), length);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-08-13 02:29:07 +02:00
|
|
|
@Override
|
|
|
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
return unwrap().nioBuffers(idx(index), length);
|
2013-06-13 05:40:26 +02:00
|
|
|
}
|
2013-06-27 10:36:22 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-01 01:23:52 +02:00
|
|
|
public int forEachByte(int index, int length, ByteProcessor processor) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
int ret = unwrap().forEachByte(idx(index), length, processor);
|
2013-06-27 11:48:09 +02:00
|
|
|
if (ret >= adjustment) {
|
|
|
|
return ret - adjustment;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-01 01:23:52 +02:00
|
|
|
public int forEachByteDesc(int index, int length, ByteProcessor processor) {
|
2015-10-16 13:20:51 +02:00
|
|
|
checkIndex0(index, length);
|
2016-04-13 13:34:39 +02:00
|
|
|
int ret = unwrap().forEachByteDesc(idx(index), length, processor);
|
2013-06-27 10:49:46 +02:00
|
|
|
if (ret >= adjustment) {
|
|
|
|
return ret - adjustment;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 14:49:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index with the needed adjustment.
|
|
|
|
*/
|
|
|
|
final int idx(int index) {
|
|
|
|
return index + adjustment;
|
|
|
|
}
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|