This commit introduces DataBuffer.indexOf(IntPredicate) and
lastIndexOf(IntPredicate), for finding the index of a byte in a
DataBuffer.
It also introduces DataBufferUtils.tokenize, which tokenizes a
DataBuffer into separate tokens, given a delimiter function.
@ -82,8 +83,25 @@ public class DefaultDataBuffer implements DataBuffer {
@@ -82,8 +83,25 @@ public class DefaultDataBuffer implements DataBuffer {
}
@Override
publicbyteget(intindex){
returnthis.byteBuffer.get(index);
publicintindexOf(IntPredicatepredicate){
for(inti=0;i<readableByteCount();i++){
byteb=this.byteBuffer.get(i);
if(predicate.test(b)){
returni;
}
}
return-1;
}
@Override
publicintlastIndexOf(IntPredicatepredicate){
for(inti=readableByteCount()-1;i>=0;i--){
byteb=this.byteBuffer.get(i);
if(predicate.test(b)){
returni;
}
}
return-1;
}
@Override
@ -120,14 +138,16 @@ public class DefaultDataBuffer implements DataBuffer {
@@ -120,14 +138,16 @@ public class DefaultDataBuffer implements DataBuffer {
@ -68,8 +69,15 @@ public class NettyDataBuffer implements PooledDataBuffer {
@@ -68,8 +69,15 @@ public class NettyDataBuffer implements PooledDataBuffer {
@ -166,6 +174,12 @@ public class NettyDataBuffer implements PooledDataBuffer {
@@ -166,6 +174,12 @@ public class NettyDataBuffer implements PooledDataBuffer {
returnthis;
}
@Override
publicDataBufferslice(intindex,intlength){
ByteBufslice=this.byteBuf.slice(index,length);
returnnewNettyDataBuffer(slice,this.allocator);
}
@Override
publicByteBufferasByteBuffer(){
returnthis.byteBuf.nioBuffer();
@ -183,8 +197,7 @@ public class NettyDataBuffer implements PooledDataBuffer {
@@ -183,8 +197,7 @@ public class NettyDataBuffer implements PooledDataBuffer {
@ -184,7 +183,65 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
@@ -184,7 +183,65 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
@ -103,7 +106,25 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
@@ -103,7 +106,25 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {