@SneakyThrows(IOException.class)
    private ByteBuffer copyData(List<ReadResultEntryContents> contents) {
        int totalSize = contents.stream().mapToInt(ReadResultEntryContents::getLength).sum();

        ByteBuffer data = ByteBuffer.allocate(totalSize);
        int bytesCopied = 0;
        for (ReadResultEntryContents content : contents) {
            int copied = StreamHelpers.readAll(content.getData(), data.array(), bytesCopied, totalSize - bytesCopied);
            Preconditions.checkState(copied == content.getLength(), "Read fewer bytes than available.");
            bytesCopied += copied;
        }
        return data;
    }
@ SneakyThrows ( IOException . class ) private ByteBuffer copyData ( List < ReadResultEntryContents > contents ) { int totalSize = contents . stream ( ) . mapToInt ( ReadResultEntryContents :: getLength ) . sum ( ) ; ByteBuffer data = ByteBuffer . allocate ( totalSize ) ; int bytesCopied = 0 ; for ( ReadResultEntryContents content : contents ) { int copied = StreamHelpers . readAll ( content . getData ( ) , data . array ( ) , bytesCopied , totalSize - bytesCopied ) ; Preconditions . checkState ( copied == content . getLength ( ) , "Read fewer bytes than available." ) ; bytesCopied += copied ; } return data ; }
Copy all of the contents provided into a byteBuffer and return it.