List of utility methods to do ByteBuffer Concatenate
ByteBuffer | concat(byte[] pre, ByteBuffer bbuf) concat ByteBuffer b = reserve(pre.length, bbuf);
b.put(pre);
rewind(b);
return b;
|
ByteBuffer | concat(ByteBuffer b1, ByteBuffer b2) Allocates a new ByteBuffer with a capacity of the sum of the ByteBuffer#limit() of the two given ByteBuffers and cancatinates them together. int capacity = ((b1.limit() == 0 ? b1.capacity() : b1.limit())) + ((b2.limit() == 0 ? b2.capacity() : b2.limit())); ByteBuffer dst; if (b1.isDirect() || b2.isDirect()) { dst = ByteBuffer.allocateDirect(capacity); } else { dst = ByteBuffer.allocate(capacity); b1.rewind(); dst.put(b1); b2.rewind(); dst.put(b2); return dst; |
byte[] | concat(ByteBuffer outPart1, ByteBuffer outPart2) concat return concat(getByteArray(outPart1), getByteArray(outPart2));
|
ByteBuffer[] | concat(ByteBuffer[] buf1, ByteBuffer[] buf2) concat ByteBuffer[] buf = new ByteBuffer[buf1.length + buf2.length]; int j = 0; for (int i = 0, len = buf1.length; i < len; i++) { buf[j++] = buf1[i]; for (int i = 0, len = buf2.length; i < len; i++) { buf[j++] = buf2[i]; return buf; |
ByteBuffer[] | concat(ByteBuffer[] buffers, ByteBuffer buffer) concat return concat(buffers, new ByteBuffer[] { buffer }); |
ByteBuffer | concat(ByteBuffer[] buffers, int overAllCapacity) Merge all byte buffers together ByteBuffer all = ByteBuffer.allocateDirect(overAllCapacity); for (int i = 0; i < buffers.length; i++) { ByteBuffer curr = buffers[i].slice(); all.put(curr); all.rewind(); return all; |
ByteBuffer | concat(List Concatenates one or more byte buffers to one large buffer. long length = 0; for (ByteBuffer bb : bbs) { bb.rewind(); length += bb.remaining(); if (length > Integer.MAX_VALUE) { throw new IllegalArgumentException("Buffers are too large for concatenation"); if (length == 0) { return EMPTY; ByteBuffer bbNew = ByteBuffer.allocateDirect((int) length); for (ByteBuffer bb : bbs) { bb.rewind(); bbNew.put(bb); bbNew.rewind(); return bbNew; |
ByteBuffer | concatenateBytebuffers(ArrayList concatenate nio-ByteBuffers int n = 0; for (ByteBuffer b : buffers) n += b.remaining(); ByteBuffer buf = (n > 0 && buffers.get(0).isDirect()) ? ByteBuffer.allocateDirect(n) : ByteBuffer.allocate(n); if (n > 0) buf.order(buffers.get(0).order()); for (ByteBuffer b : buffers) ... |