diff --git a/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java index 0b7a0fbab6..cd72ffa4a8 100644 --- a/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java @@ -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); diff --git a/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java index 69b5907fbe..537cf5eabe 100644 --- a/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/ChannelBuffer.java @@ -604,6 +604,8 @@ public interface ChannelBuffer extends Comparable { 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); diff --git a/src/main/java/org/jboss/netty/handler/codec/replay/ReplayingDecoderBuffer.java b/src/main/java/org/jboss/netty/handler/codec/replay/ReplayingDecoderBuffer.java index 2548d68ea1..6108795bd9 100644 --- a/src/main/java/org/jboss/netty/handler/codec/replay/ReplayingDecoderBuffer.java +++ b/src/main/java/org/jboss/netty/handler/codec/replay/ReplayingDecoderBuffer.java @@ -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(); }