Added ChannelBuffer.readSlice() methods in case a user doesn't want to copy at the risk of modified content
This commit is contained in:
parent
b33bbf7da7
commit
289e84d69c
@ -224,6 +224,20 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
return readBytes(endIndex);
|
||||
}
|
||||
|
||||
public ChannelBuffer readSlice(int length) {
|
||||
ChannelBuffer slice = slice(readerIndex, length);
|
||||
readerIndex += length;
|
||||
return slice;
|
||||
}
|
||||
|
||||
public ChannelBuffer readSlice(ChannelBufferIndexFinder endIndexFinder) {
|
||||
int endIndex = indexOf(readerIndex, writerIndex, endIndexFinder);
|
||||
if (endIndex < 0) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return readSlice(endIndex);
|
||||
}
|
||||
|
||||
public void readBytes(byte[] dst, int dstIndex, int length) {
|
||||
checkReadableBytes(length);
|
||||
getBytes(readerIndex, dst, dstIndex, length);
|
||||
|
@ -604,6 +604,8 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
|
||||
ChannelBuffer readBytes(int length);
|
||||
ChannelBuffer readBytes(ChannelBufferIndexFinder endIndexFinder);
|
||||
ChannelBuffer readSlice(int length);
|
||||
ChannelBuffer readSlice(ChannelBufferIndexFinder endIndexFinder);
|
||||
void readBytes(ChannelBuffer dst);
|
||||
void readBytes(ChannelBuffer dst, int length);
|
||||
void readBytes(ChannelBuffer dst, int dstIndex, int length);
|
||||
|
@ -246,6 +246,20 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
|
||||
return buffer.readBytes(length);
|
||||
}
|
||||
|
||||
public ChannelBuffer readSlice(
|
||||
ChannelBufferIndexFinder endIndexFinder) {
|
||||
int endIndex = buffer.indexOf(buffer.readerIndex(), buffer.writerIndex(), endIndexFinder);
|
||||
if (endIndex < 0) {
|
||||
throw REPLAY;
|
||||
}
|
||||
return readSlice(endIndex);
|
||||
}
|
||||
|
||||
public ChannelBuffer readSlice(int length) {
|
||||
checkReadableBytes(length);
|
||||
return buffer.readSlice(length);
|
||||
}
|
||||
|
||||
public void readBytes(OutputStream out, int length) throws IOException {
|
||||
reject();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user