private final ByteArrayOutputStream getByteArrayStream ( ) { ByteArrayOutputStream rtnBaos = null ; // Get a ByteArrayOutputStream from the pool. Note that this must be // synchronized as multiple threads may be accessing this pool, and the // pool may return null if empty. d175235 synchronized ( svBAOSs ) { if ( svBAOSsSize > 0 ) { -- svBAOSsSize ; rtnBaos = svBAOSs [ svBAOSsSize ] ; svBAOSs [ svBAOSsSize ] = null ; } } // If the pool was empty, then new up a new one (outside the synchronized // block for performance), otherwise reset the one form the pool. d175235 if ( rtnBaos == null ) { rtnBaos = new ByteArrayOutputStream ( ) ; } else { // clear the byte array and reset back to zero. rtnBaos . reset ( ) ; } return rtnBaos ; }
Return the next available ByteArrayOutputStream object from the pool .