MCPcopy
hub / github.com/google/guava / combineBuffers

Method combineBuffers

guava/src/com/google/common/io/ByteStreams.java:211–229  ·  guava/src/com/google/common/io/ByteStreams.java::ByteStreams.combineBuffers
(Queue<byte[]> bufs, int totalLen)

Source from the content-addressed store, hash-verified

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.

Callers 1

toByteArrayInternalMethod · 0.95

Calls 4

isEmptyMethod · 0.65
removeMethod · 0.65
copyOfMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected