Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public int writeCharSequence(CharSequence sequence, Charset charset) {

@Override
public ByteBuffer internalNioBuffer(int index, int length) {
throw new UnsupportedOperationException();
return nioBuffer(index, length);
}

@Override
Expand Down
24 changes: 13 additions & 11 deletions rsocket-core/src/main/java/io/rsocket/buffer/Tuple2ByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ public ByteBuffer[] _nioBuffers(int index, int length) {

@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
checkDstIndex(index, length, dstIndex, dst.capacity());
if (length == 0) {
return this;
}

// FIXME: check twice here
long ri = calculateRelativeIndex(index);
index = (int) (ri & Integer.MAX_VALUE);
switch ((int) ((ri & MASK) >>> 32L)) {
Expand Down Expand Up @@ -165,20 +171,22 @@ public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
@Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
ByteBuf dstBuf = Unpooled.wrappedBuffer(dst);
int min = Math.min(dst.length, capacity);
return getBytes(0, dstBuf, index, min);
return getBytes(index, dstBuf, dstIndex, length);
}

@Override
public ByteBuf getBytes(int index, ByteBuffer dst) {
ByteBuf dstBuf = Unpooled.wrappedBuffer(dst);
int min = Math.min(dst.limit(), capacity);
return getBytes(0, dstBuf, index, min);
return getBytes(index, dstBuf);
}

@Override
public ByteBuf getBytes(int index, final OutputStream out, int length) throws IOException {
checkIndex(index, length);
if (length == 0) {
return this;
}

long ri = calculateRelativeIndex(index);
index = (int) (ri & Integer.MAX_VALUE);
switch ((int) ((ri & MASK) >>> 32L)) {
Expand Down Expand Up @@ -354,18 +362,12 @@ protected void deallocate() {

@Override
public String toString(Charset charset) {
StringBuilder builder = new StringBuilder(3);
StringBuilder builder = new StringBuilder(capacity);
builder.append(one.toString(charset));
builder.append(two.toString(charset));
return builder.toString();
}

@Override
public String toString(int index, int length, Charset charset) {
// TODO - make this smarter
return toString(charset).substring(index, length);
}

@Override
public String toString() {
return "Tuple2ByteBuf{"
Expand Down
12 changes: 2 additions & 10 deletions rsocket-core/src/main/java/io/rsocket/buffer/Tuple3ByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,13 @@ public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
@Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
ByteBuf dstBuf = Unpooled.wrappedBuffer(dst);
int min = Math.min(dst.length, capacity);
return getBytes(0, dstBuf, index, min);
return getBytes(index, dstBuf, dstIndex, length);
}

@Override
public ByteBuf getBytes(int index, ByteBuffer dst) {
ByteBuf dstBuf = Unpooled.wrappedBuffer(dst);
int min = Math.min(dst.limit(), capacity);
return getBytes(0, dstBuf, index, min);
return getBytes(index, dstBuf);
}

@Override
Expand Down Expand Up @@ -539,12 +537,6 @@ public String toString(Charset charset) {
return builder.toString();
}

@Override
public String toString(int index, int length, Charset charset) {
// TODO - make this smarter
return toString(charset).substring(index, length);
}

@Override
public String toString() {
return "Tuple3ByteBuf{"
Expand Down
Loading