void grow ( int neededSize ) { if ( neededSize < 0 ) { throw new IllegalArgumentException ( "Cannot grow BufferHolder by size " + neededSize + " because the size is negative" ) ; } if ( neededSize > ARRAY_MAX - totalSize ( ) ) { throw new IllegalArgumentException ( "Cannot grow BufferHolder by size " + neededSize + " because the size after growing " + "exceeds size limitation " + ARRAY_MAX ) ; } final int length = totalSize ( ) + neededSize ; if ( buffer . length < length ) { // This will not happen frequently, because the buffer is re-used. int newLength = length < ARRAY_MAX / 2 ? length * 2 : ARRAY_MAX ; int roundedSize = ByteArrayMethods . roundNumberOfBytesToNearestWord ( newLength ) ; final byte [ ] tmp = new byte [ roundedSize ] ; Platform . copyMemory ( buffer , Platform . BYTE_ARRAY_OFFSET , tmp , Platform . BYTE_ARRAY_OFFSET , totalSize ( ) ) ; buffer = tmp ; row . pointTo ( buffer , buffer . length ) ; } }
Grows the buffer by at least neededSize and points the row to the buffer .