public ByteBuffer getByteBuffer() { List<ByteBuffer> list = getBufferList(); // if there's just one bytebuffer in list, return it if (list.size() == 1) { return list.get(0); } int size = 0; for (ByteBuffer buffer : list) { size += buffer.remaining(); } ByteBuffer result = ByteBuffer.allocate(size); for (ByteBuffer buffer : list) { result.put(buffer); } return (ByteBuffer) result.rewind(); }