public int shrink ( ) { byte [ ] old = buf ; if ( pos == 0 ) { return 0 ; // nothing to do } int n = old . length - pos ; int m ; int p ; int s ; int l ; if ( n < origsize ) { buf = new byte [ origsize ] ; p = pos ; s = origsize - n ; l = old . length - p ; m = old . length - origsize ; pos = s ; } else { buf = new byte [ n ] ; p = pos ; s = 0 ; l = n ; m = old . length - l ; pos = 0 ; } System . arraycopy ( old , p , buf , s , l ) ; return m ; }
Shrink the buffer . This will reclaim currently unused space in the buffer reducing memory but potentially increasing the cost of resizing the buffer