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
|
|
|
|
2012-10-18 08:57:23 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.nio.ByteBuffer;
|
2008-08-08 02:37:18 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* A {@link ByteBuf} which is composed out of other {@link ByteBuf}s.
|
|
|
|
*/
|
2012-07-20 05:33:17 +02:00
|
|
|
public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* Add the given {@link ByteBuf}.
|
|
|
|
*
|
2013-03-25 10:58:50 +01:00
|
|
|
* Be aware that this method does not increase the {@code writerIndex} of the {@link CompositeByteBuf}.
|
|
|
|
* If you need to have it increased you need to handle it by your own.
|
|
|
|
*
|
2012-12-21 22:22:40 +01:00
|
|
|
* @param buffer the {@link ByteBuf} to add
|
|
|
|
* @return self this instance
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf addComponent(ByteBuf buffer);
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given {@link ByteBuf} on the specific index.
|
|
|
|
*
|
2013-03-25 10:58:50 +01:00
|
|
|
* Be aware that this method does not increase the {@code writerIndex} of the {@link CompositeByteBuf}.
|
|
|
|
* If you need to have it increased you need to handle it by your own.
|
|
|
|
*
|
2012-12-21 22:22:40 +01:00
|
|
|
* @param cIndex
|
|
|
|
* the index on which the {@link ByteBuf} will be added
|
|
|
|
* @param buffer
|
|
|
|
* the {@link ByteBuf} to add
|
|
|
|
* @return self
|
|
|
|
* this instance
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the index is invalid
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf addComponent(int cIndex, ByteBuf buffer);
|
2012-07-20 06:18:17 +02:00
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* Add the given {@link ByteBuf}s.
|
|
|
|
*
|
2013-03-25 10:58:50 +01:00
|
|
|
* Be aware that this method does not increase the {@code writerIndex} of the {@link CompositeByteBuf}.
|
|
|
|
* If you need to have it increased you need to handle it by your own.
|
|
|
|
*
|
2012-12-21 22:22:40 +01:00
|
|
|
* @param buffers the {@link ByteBuf}s to add
|
|
|
|
* @return self this instance
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf addComponents(ByteBuf... buffers);
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given {@link ByteBuf}s.
|
|
|
|
*
|
2013-03-25 10:58:50 +01:00
|
|
|
* Be aware that this method does not increase the {@code writerIndex} of the {@link CompositeByteBuf}.
|
|
|
|
* If you need to have it increased you need to handle it by your own.
|
|
|
|
*
|
2012-12-21 22:22:40 +01:00
|
|
|
* @param buffers the {@link ByteBuf}s to add
|
|
|
|
* @return self this instance
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf addComponents(Iterable<ByteBuf> buffers);
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given {@link ByteBuf}s on the specific index
|
|
|
|
*
|
2013-03-25 10:58:50 +01:00
|
|
|
* Be aware that this method does not increase the {@code writerIndex} of the {@link CompositeByteBuf}.
|
|
|
|
* If you need to have it increased you need to handle it by your own.
|
|
|
|
*
|
2012-12-21 22:22:40 +01:00
|
|
|
* @param cIndex
|
|
|
|
* the index on which the {@link ByteBuf} will be added.
|
|
|
|
* @param buffers
|
|
|
|
* the {@link ByteBuf}s to add
|
|
|
|
* @return self
|
|
|
|
* this instance
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the index is invalid
|
|
|
|
*
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf addComponents(int cIndex, ByteBuf... buffers);
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the given {@link ByteBuf}s on the specific index
|
|
|
|
*
|
2013-03-25 10:58:50 +01:00
|
|
|
* Be aware that this method does not increase the {@code writerIndex} of the {@link CompositeByteBuf}.
|
|
|
|
* If you need to have it increased you need to handle it by your own.
|
|
|
|
*
|
2012-12-21 22:22:40 +01:00
|
|
|
* @param cIndex
|
|
|
|
* the index on which the {@link ByteBuf} will be added.
|
|
|
|
* @param buffers
|
|
|
|
* the {@link ByteBuf}s to add
|
|
|
|
* @return self
|
|
|
|
* this instance
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the index is invalid
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf addComponents(int cIndex, Iterable<ByteBuf> buffers);
|
2012-07-20 06:18:17 +02:00
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* Remove the {@link ByteBuf} from the given index.
|
|
|
|
*
|
|
|
|
* @param cIndex
|
|
|
|
* the index on from which the {@link ByteBuf} will be remove
|
|
|
|
* @return self
|
|
|
|
* this instance
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the index is invalid
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf removeComponent(int cIndex);
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the number of {@link ByteBuf}s starting from the given index.
|
|
|
|
*
|
|
|
|
* @param cIndex
|
|
|
|
* the index on which the {@link ByteBuf}s will be started to removed
|
|
|
|
* @param numComponents
|
|
|
|
* the number of components to remove
|
|
|
|
* @return self
|
|
|
|
* this instance
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the index is invalid
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf removeComponents(int cIndex, int numComponents);
|
2009-12-30 04:14:50 +01:00
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* Return the current number of {@link ByteBuf}'s that are composed in this instance
|
|
|
|
*/
|
2012-07-19 13:23:55 +02:00
|
|
|
int numComponents();
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the max number of {@link ByteBuf}'s that are composed in this instance
|
|
|
|
*/
|
2012-07-19 13:23:55 +02:00
|
|
|
int maxNumComponents();
|
2009-12-30 04:14:50 +01:00
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* Return the {@link ByteBuf} on the specified index
|
|
|
|
*
|
|
|
|
* @param cIndex
|
|
|
|
* the index for which the {@link ByteBuf} should be returned
|
|
|
|
* @return buf
|
|
|
|
* the {@link ByteBuf} on the specified index
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the index is invalid
|
|
|
|
*/
|
2012-07-19 13:23:55 +02:00
|
|
|
ByteBuf component(int cIndex);
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the {@link ByteBuf} on the specified index
|
|
|
|
*
|
|
|
|
* @param offset
|
|
|
|
* the offset for which the {@link ByteBuf} should be returned
|
|
|
|
* @return buf
|
|
|
|
* the {@link ByteBuf} on the specified index
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the offset is invalid
|
|
|
|
*/
|
2012-07-19 13:23:55 +02:00
|
|
|
ByteBuf componentAtOffset(int offset);
|
2009-12-30 04:14:50 +01:00
|
|
|
|
2013-07-05 07:00:05 +02:00
|
|
|
/**
|
|
|
|
* Return the internal {@link ByteBuf} on the specified index. Note that updating the indexes of the returned
|
|
|
|
* buffer will lead to an undefined behavior of this buffer.
|
|
|
|
*
|
|
|
|
* @param cIndex the index for which the {@link ByteBuf} should be returned
|
|
|
|
*/
|
|
|
|
ByteBuf internalComponent(int cIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the internal {@link ByteBuf} on the specified offset. Note that updating the indexes of the returned
|
|
|
|
* buffer will lead to an undefined behavior of this buffer.
|
|
|
|
*
|
|
|
|
* @param offset the offset for which the {@link ByteBuf} should be returned
|
|
|
|
*/
|
|
|
|
ByteBuf internalComponentAtOffset(int offset);
|
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* Discard all {@link ByteBuf}s which are read.
|
|
|
|
*
|
|
|
|
* @return self this instance
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf discardReadComponents();
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Consolidate the composed {@link ByteBuf}s
|
|
|
|
*
|
|
|
|
* @return self this instance
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf consolidate();
|
2012-12-21 22:22:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Consolidate the composed {@link ByteBuf}s
|
|
|
|
*
|
|
|
|
* @param cIndex
|
|
|
|
* the index on which to start to compose
|
|
|
|
* @param numComponents
|
|
|
|
* the number of components to compose
|
|
|
|
* @return self
|
|
|
|
* this instance
|
2013-01-31 15:28:08 +01:00
|
|
|
* @throws IndexOutOfBoundsException
|
2012-12-21 22:22:40 +01:00
|
|
|
* if the offset is invalid
|
|
|
|
*/
|
2012-10-18 08:57:23 +02:00
|
|
|
CompositeByteBuf consolidate(int cIndex, int numComponents);
|
2009-12-30 04:14:50 +01:00
|
|
|
|
2012-12-21 22:22:40 +01:00
|
|
|
/**
|
|
|
|
* Return the index for the given offset
|
|
|
|
*/
|
2012-07-19 13:23:55 +02:00
|
|
|
int toComponentIndex(int offset);
|
2012-12-21 22:22:40 +01:00
|
|
|
|
2012-07-19 13:23:55 +02:00
|
|
|
int toByteIndex(int cIndex);
|
2009-12-30 04:14:50 +01:00
|
|
|
|
|
|
|
/**
|
2012-07-19 13:23:55 +02:00
|
|
|
* Same with {@link #slice(int, int)} except that this method returns a list.
|
2012-06-28 11:00:43 +02:00
|
|
|
*/
|
2012-07-19 13:23:55 +02:00
|
|
|
List<ByteBuf> decompose(int offset, int length);
|
2012-10-18 08:57:23 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf capacity(int newCapacity);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readerIndex(int readerIndex);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writerIndex(int writerIndex);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setIndex(int readerIndex, int writerIndex);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf clear();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf markReaderIndex();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf resetReaderIndex();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf markWriterIndex();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf resetWriterIndex();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf discardReadBytes();
|
|
|
|
|
2012-12-17 09:41:21 +01:00
|
|
|
@Override
|
|
|
|
CompositeByteBuf discardSomeReadBytes();
|
|
|
|
|
2012-10-18 08:57:23 +02:00
|
|
|
@Override
|
2013-01-31 15:28:08 +01:00
|
|
|
CompositeByteBuf ensureWritable(int minWritableBytes);
|
2012-10-18 08:57:23 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf getBytes(int index, ByteBuf dst);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf getBytes(int index, ByteBuf dst, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf getBytes(int index, byte[] dst);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf getBytes(int index, byte[] dst, int dstIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf getBytes(int index, ByteBuffer dst);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf getBytes(int index, OutputStream out, int length) throws IOException;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setBoolean(int index, boolean value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setByte(int index, int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setShort(int index, int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setMedium(int index, int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setInt(int index, int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setLong(int index, long value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setChar(int index, int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setFloat(int index, float value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setDouble(int index, double value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setBytes(int index, ByteBuf src);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setBytes(int index, ByteBuf src, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setBytes(int index, byte[] src);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setBytes(int index, byte[] src, int srcIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setBytes(int index, ByteBuffer src);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf setZero(int index, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readBytes(ByteBuf dst);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readBytes(ByteBuf dst, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readBytes(ByteBuf dst, int dstIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readBytes(byte[] dst);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readBytes(byte[] dst, int dstIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readBytes(ByteBuffer dst);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf readBytes(OutputStream out, int length) throws IOException;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf skipBytes(int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeBoolean(boolean value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeByte(int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeShort(int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeMedium(int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeInt(int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeLong(long value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeChar(int value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeFloat(float value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeDouble(double value);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeBytes(ByteBuf src);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeBytes(ByteBuf src, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeBytes(ByteBuf src, int srcIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeBytes(byte[] src);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeBytes(byte[] src, int srcIndex, int length);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeBytes(ByteBuffer src);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf writeZero(int length);
|
|
|
|
|
2013-02-13 08:09:33 +01:00
|
|
|
@Override
|
|
|
|
CompositeByteBuf retain(int increment);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
CompositeByteBuf retain();
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|