Fixed a problem where ReplayingDecoderBuffer.readBytes/readSlice() and AbstractChannelBuffer.readSlice() doesn't work properly.

This commit is contained in:
Trustin Lee 2008-12-06 14:19:56 +00:00
parent 549145687e
commit 414e02cb3e
2 changed files with 6 additions and 5 deletions

View File

@ -267,6 +267,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
if (length == 0) {
return ChannelBuffers.EMPTY_BUFFER;
}
// TODO: Allow a user to specify the buffer factory as an overloaded method.
ChannelBuffer buf = ChannelBuffers.buffer(order(), length);
buf.writeBytes(this, readerIndex, length);
readerIndex += length;
@ -278,7 +279,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
if (endIndex < 0) {
throw new NoSuchElementException();
}
return readBytes(endIndex);
return readBytes(endIndex - readerIndex);
}
public ChannelBuffer readSlice(int length) {
@ -292,7 +293,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
if (endIndex < 0) {
throw new NoSuchElementException();
}
return readSlice(endIndex);
return readSlice(endIndex - readerIndex);
}
public void readBytes(byte[] dst, int dstIndex, int length) {

View File

@ -57,7 +57,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
public void clear() {
reject();
}
@Override
public boolean equals(Object obj) {
return this == obj;
@ -255,7 +255,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
if (endIndex < 0) {
throw REPLAY;
}
return readBytes(endIndex);
return buffer.readBytes(endIndex - buffer.readerIndex());
}
public int readBytes(GatheringByteChannel out, int length)
@ -275,7 +275,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
if (endIndex < 0) {
throw REPLAY;
}
return readSlice(endIndex);
return buffer.readSlice(endIndex - buffer.readerIndex());
}
public ChannelBuffer readSlice(int length) {