(Queue<byte[]> bufs, int totalLen)
| 209 | } |
| 210 | |
| 211 | private static byte[] combineBuffers(Queue<byte[]> bufs, int totalLen) { |
| 212 | if (bufs.isEmpty()) { |
| 213 | return new byte[0]; |
| 214 | } |
| 215 | byte[] result = bufs.remove(); |
| 216 | if (result.length == totalLen) { |
| 217 | return result; |
| 218 | } |
| 219 | int remaining = totalLen - result.length; |
| 220 | result = Arrays.copyOf(result, totalLen); |
| 221 | while (remaining > 0) { |
| 222 | byte[] buf = bufs.remove(); |
| 223 | int bytesToCopy = min(remaining, buf.length); |
| 224 | int resultOffset = totalLen - remaining; |
| 225 | System.arraycopy(buf, 0, result, resultOffset, bytesToCopy); |
| 226 | remaining -= bytesToCopy; |
| 227 | } |
| 228 | return result; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Reads all bytes from an input stream into a byte array. Does not close the stream. |
no test coverage detected