void ensureCapacity ( final int bytesAmount ) { if ( currentByteArrayIndex + bytesAmount >= serializedData . length ) { // +1 ensures proper behavior for 0 estimate. int newSerializedDataArrayLength = ( serializedData . length + 1 ) * 2 ; while ( currentByteArrayIndex + bytesAmount >= newSerializedDataArrayLength ) { newSerializedDataArrayLength = newSerializedDataArrayLength * 2 ; } final byte [ ] newSerializedDataArray = new byte [ newSerializedDataArrayLength ] ; // Arrays.copyOf is not emulated on GWT. System . arraycopy ( serializedData , 0 , newSerializedDataArray , 0 , currentByteArrayIndex ) ; serializedData = newSerializedDataArray ; } }
Resizes original byte array if the object turns out to be bigger than expected .