private void grow ( int neededSize ) { if ( neededSize > ARRAY_MAX - totalSize ( ) ) { throw new UnsupportedOperationException ( "Cannot grow internal buffer by size " + neededSize + " because the size after growing " + "exceeds size limitation " + ARRAY_MAX ) ; } final int length = totalSize ( ) + neededSize ; if ( buffer . length < length ) { int newLength = length < ARRAY_MAX / 2 ? length * 2 : ARRAY_MAX ; final byte [ ] tmp = new byte [ newLength ] ; Platform . copyMemory ( buffer , Platform . BYTE_ARRAY_OFFSET , tmp , Platform . BYTE_ARRAY_OFFSET , totalSize ( ) ) ; buffer = tmp ; } }
Grows the buffer by at least neededSize