Places the data from the buffer into the array of destination
ByteBuffer objects.
if (buffer == null) {
return 0;
}
int pos = 0;
int len = buffer.length;
int rem;
// write data to the buffers
for (int i=offset; i<offset+length; i++) {
rem = dsts[i].remaining();
// TODO: optimization work - use hasArray, array(), arraycopy
if (len - pos < rem) {
// can fully write remaining data into buffer
dsts[i].put(buffer, pos, len - pos);
pos = len;
// data was written, exit
break;
} else {
// write chunk of data
dsts[i].put(buffer, pos, rem);
pos += rem;
}
}
if (pos != len) {
// The data did not feet into the buffers,
// it should not happen, because the destination buffers
// had been checked for the space before record unwrapping.
// But if it so, we should allert about internal error.
throw new AlertException(
AlertProtocol.INTERNAL_ERROR,
new SSLException(
"The received application data could not be fully written"
+ "into the destination buffers"));
}
buffer = null;
return len;