public static void writeBuffers(FileChannel channel, long bytesExpected, ByteBuffer... buffers)
            throws IOException {
        // The FileChannel#write method relies on the writev system call for data writing on linux.
        // The writev system call has a limit on the maximum number of buffers can be written in one
        // invoke whose advertised value is 1024 (see writev man page for more information), which
        // means if more than 1024 buffers is written in one invoke, it is not guaranteed that all
        // bytes can be written, so we build this safety net.
        if (bytesExpected > channel.write(buffers)) {
            for (ByteBuffer buffer : buffers) {
                writeBuffer(channel, buffer);
            }
        }
    }
@Test
    void testBulkWritingLargeNumberOfBuffers(@TempDir Path tempPath) throws Exception {
        int bufferSize = 1024;
        int numBuffers = 1025;
        try (FileChannel fileChannel = tmpFileChannel(tempPath)) {
            ByteBuffer[] data = new ByteBuffer[numBuffers];
            for (int i = 0; i < numBuffers; ++i) {
                data[i] = ByteBuffer.allocateDirect(bufferSize);
            }
            int bytesExpected = bufferSize * numBuffers;
            BufferReaderWriterUtil.writeBuffers(fileChannel, bytesExpected, data);
            assertThat(fileChannel.size()).isEqualTo(bytesExpected);
        }
    }