Skip to content

Commit

Permalink
[JENKINS-36871] Remove intermediary ByteBuffer.wrap for simple case
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Aug 3, 2016
1 parent bbb5865 commit d40ca3d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
28 changes: 25 additions & 3 deletions src/main/java/org/jenkinsci/remoting/util/ByteBufferQueue.java
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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.