public static byte [ ] getBytes ( MemorySegment [ ] segments , int baseOffset , int sizeInBytes ) { // avoid copy if `base` is `byte[]` if ( segments . length == 1 ) { byte [ ] heapMemory = segments [ 0 ] . getHeapMemory ( ) ; if ( baseOffset == 0 && heapMemory != null && heapMemory . length == sizeInBytes ) { return heapMemory ; } else { byte [ ] bytes = new byte [ sizeInBytes ] ; segments [ 0 ] . get ( baseOffset , bytes , 0 , sizeInBytes ) ; return bytes ; } } else { byte [ ] bytes = new byte [ sizeInBytes ] ; copyMultiSegmentsToBytes ( segments , baseOffset , bytes , 0 , sizeInBytes ) ; return bytes ; } }
Maybe not copied if want copy please use copyTo .