public static void writeBuffers(
            WritableByteChannel writeChannel, long expectedBytes, ByteBuffer[] bufferWithHeaders)
            throws IOException {
        int writeSize = 0;
        for (ByteBuffer bufferWithHeader : bufferWithHeaders) {
            writeSize += writeChannel.write(bufferWithHeader);
        }
        checkState(writeSize == expectedBytes, "Wong number of written bytes.");
    }
@Test
    void testWriteBuffers() throws IOException {
        Random random = new Random();
        int numBuffers = 20;
        int bufferSizeBytes = 10;

        File testFile = new File(tempFolder.getPath(), "testFile");
        org.apache.flink.core.fs.Path testPath =
                org.apache.flink.core.fs.Path.fromLocalFile(testFile);
        FileSystem fs = testPath.getFileSystem();
        WritableByteChannel currentChannel =
                Channels.newChannel(fs.create(testPath, FileSystem.WriteMode.NO_OVERWRITE));

        ByteBuffer[] toWriteBuffers = new ByteBuffer[numBuffers];
        for (int i = 0; i < numBuffers; i++) {
            byte[] bytes = new byte[bufferSizeBytes];
            random.nextBytes(bytes);
            toWriteBuffers[i] = ByteBuffer.wrap(bytes);
        }
        int numExpectedBytes = numBuffers * bufferSizeBytes;
        SegmentPartitionFile.writeBuffers(currentChannel, numExpectedBytes, toWriteBuffers);

        byte[] bytesRead = Files.readAllBytes(testFile.toPath());
        assertThat(bytesRead).hasSize(numExpectedBytes);
    }