@@ -134,6 +134,12 @@ public ByteBuffer[] _nioBuffers(int index, int length) {
134
134
135
135
@ Override
136
136
public ByteBuf getBytes (int index , ByteBuf dst , int dstIndex , int length ) {
137
+ checkDstIndex (index , length , dstIndex , dst .capacity ());
138
+ if (length == 0 ) {
139
+ return this ;
140
+ }
141
+
142
+ // FIXME: check twice here
137
143
long ri = calculateRelativeIndex (index );
138
144
index = (int ) (ri & Integer .MAX_VALUE );
139
145
switch ((int ) ((ri & MASK ) >>> 32L )) {
@@ -165,20 +171,22 @@ public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
165
171
@ Override
166
172
public ByteBuf getBytes (int index , byte [] dst , int dstIndex , int length ) {
167
173
ByteBuf dstBuf = Unpooled .wrappedBuffer (dst );
168
- int min = Math .min (dst .length , capacity );
169
- return getBytes (0 , dstBuf , index , min );
174
+ return getBytes (index , dstBuf , dstIndex , length );
170
175
}
171
176
172
177
@ Override
173
178
public ByteBuf getBytes (int index , ByteBuffer dst ) {
174
179
ByteBuf dstBuf = Unpooled .wrappedBuffer (dst );
175
- int min = Math .min (dst .limit (), capacity );
176
- return getBytes (0 , dstBuf , index , min );
180
+ return getBytes (index , dstBuf );
177
181
}
178
182
179
183
@ Override
180
184
public ByteBuf getBytes (int index , final OutputStream out , int length ) throws IOException {
181
185
checkIndex (index , length );
186
+ if (length == 0 ) {
187
+ return this ;
188
+ }
189
+
182
190
long ri = calculateRelativeIndex (index );
183
191
index = (int ) (ri & Integer .MAX_VALUE );
184
192
switch ((int ) ((ri & MASK ) >>> 32L )) {
@@ -354,18 +362,12 @@ protected void deallocate() {
354
362
355
363
@ Override
356
364
public String toString (Charset charset ) {
357
- StringBuilder builder = new StringBuilder (3 );
365
+ StringBuilder builder = new StringBuilder (capacity );
358
366
builder .append (one .toString (charset ));
359
367
builder .append (two .toString (charset ));
360
368
return builder .toString ();
361
369
}
362
370
363
- @ Override
364
- public String toString (int index , int length , Charset charset ) {
365
- // TODO - make this smarter
366
- return toString (charset ).substring (index , length );
367
- }
368
-
369
371
@ Override
370
372
public String toString () {
371
373
return "Tuple2ByteBuf{"
0 commit comments