Skip to content
Permalink
Browse files
[JENKINS-36871] Remove intermediary ByteBuffer.wrap for simple case
  • Loading branch information
stephenc committed Aug 3, 2016
1 parent bbb5865 commit d40ca3d1870174d017a432b0f85ca40f3ee8c270
Showing 2 changed files with 26 additions and 12 deletions.
@@ -169,6 +169,30 @@ public void put(ByteBuffer src) {
}
}

/**
* This method appends bytes from the byte array onto this buffer queue.
*
* @param src the source byte array.
* @param offset the offset from which to start taking bytes.
* @param len the number of bytes to transfer.
*/
public void put(byte[] src, int offset, int len) {
while (len > 0) {
while (!buffers[writeIndex].hasRemaining()) {
addWriteBuffer();
}
int remaining = buffers[writeIndex].remaining();
if (len > remaining) {
buffers[writeIndex].put(src, offset, remaining);
offset += remaining;
len -= remaining;
} else {
buffers[writeIndex].put(src, offset, len);
return;
}
}
}

/**
* This method appends a single byte onto this buffer queue.
*
@@ -373,11 +397,9 @@ public int get(byte[] dst, int offset, int len) {
int count = buffers[readIndex].remaining();
if (count > len) {
buffers[readIndex].get(dst, offset, len);
offset += len;
read += len;
len = 0;
buffers[readIndex].compact();
break;
return read;
} else {
buffers[readIndex].get(dst, offset, count);
offset += count;
@@ -56,19 +56,11 @@ public void write(int b) throws IOException {
queue.put((byte) b);
}

/**
* {@inheritDoc}
*/
@Override
public void write(byte[] b) throws IOException {
queue.put(ByteBuffer.wrap(b));
}

/**
* {@inheritDoc}
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
queue.put(ByteBuffer.wrap(b, off, len));
queue.put(b, off, len);
}
}

0 comments on commit d40ca3d

Please sign in to comment.