public synchronized byte [ ] getBuf ( int len ) { for ( int i = 0 ; i < mBuffersBySize . size ( ) ; i ++ ) { byte [ ] buf = mBuffersBySize . get ( i ) ; if ( buf . length >= len ) { mCurrentSize -= buf . length ; mBuffersBySize . remove ( i ) ; mBuffersByLastUse . remove ( buf ) ; return buf ; } } return new byte [ len ] ; }
Returns a buffer from the pool if one is available in the requested size or allocates a new one if a pooled one is not available .