Releases a temporary buffer by returning to the cache or freeing it. If
returning to the cache then insert it at the end. This makes it
suitable for scatter/gather operations where the buffers are returned to
cache in same order that they were obtained.
556762
static void offerLastTemporaryDirectBuffer(ByteBuffer buf) {
        assert buf != null;
        BufferCache cache = bufferCache.get();
        if (!cache.offerLast(buf)) {
            // cache is full
            free(buf);
        }
    }
351893
def _flush(self, buffer):
        
        if not self.state.should_try():
            logger.error("dropping flushed data due to transport failure back-off")
        else:
            fileobj = buffer.fileobj  # get a reference to the fileobj before closing the gzip file
            buffer.close()

            # StringIO on Python 2 does not have getbuffer, so we need to fall back to getvalue
            data = fileobj.getbuffer() if hasattr(fileobj, "getbuffer") else fileobj.getvalue()
            try:
                self.send(data)
                self.handle_transport_success()
            except Exception as e:
                self.handle_transport_fail(e)
1163851
public void allowDetachToRelease(boolean allowRelease)
  {
  	if((false == allowRelease) && !hasCache())
  	{
  		setShouldCacheNodes(true);
  	}
  	
  	if(null != m_iter)
  		m_iter.allowDetachToRelease(allowRelease);
  	super.allowDetachToRelease(allowRelease);
  }
133851
protected WsByteBuffer[] flushCache(WsByteBuffer[] buffers) {
        // PK13351 - use the offset/length version to write only what we need
        // to and avoid the extra memory allocation
        int pos = this.bytePosition;
        if (0 == pos) {
            // nothing to write
            return buffers;
        }
        this.bytePosition = 0;
        return GenericUtils.putByteArray(buffers, this.byteCache, 0, pos, this);
    }
1089483
WrappedByteBuffer expandAt(int i, int expectedRemaining) {
        if ((i + expectedRemaining) <= _buf.limit()) {
            return this;
        } else {
            if ((i + expectedRemaining) <= _buf.capacity()) {
                _buf.limit(i + expectedRemaining);
            } else {
                // reallocate the underlying byte buffer and keep the original buffer
                // intact. The resetting of the position is required because, one
                // could be in the middle of a read of an existing buffer, when they
                // decide to over write only few bytes but still keep the remaining
                // part of the buffer unchanged.
                int newCapacity = _buf.capacity()
                        + ((expectedRemaining > INITIAL_CAPACITY) ? expectedRemaining : INITIAL_CAPACITY);
                java.nio.ByteBuffer newBuffer = java.nio.ByteBuffer.allocate(newCapacity);
                _buf.flip();
                newBuffer.put(_buf);
                _buf = newBuffer;
            }
        }

        return this;
    }
1247655
public void clear() {
    if (cache == null) {
      return;
    }
    synchronized (cache) {
      inFlushAll = true;
      cache.invalidateAll();
      out.clear();
      inFlushAll = false;
    }
  }
756212
public static void releaseCache(URI cache, Configuration conf, long timeStamp)
    throws IOException {
    String cacheId = getKey(cache, conf, timeStamp);

    synchronized (cachedArchives) {
      CacheStatus lcacheStatus = cachedArchives.get(cacheId);
      if (lcacheStatus == null) {
        LOG.warn("Cannot find localized cache: " + cache +
                 " (key: " + cacheId + ") in releaseCache!");
        return;
      }
      lcacheStatus.refcount--;
    }
  }
797653
@Override
    public void release()
    {
        _applicationFactory = null;
        _currentFacesContext = null;
        if (_defaultExternalContext != null)
        {
            _defaultExternalContext.release();
            _defaultExternalContext = null;
        }
        
        _application = null;
        _externalContext = null;
        _viewRoot = null;
        _renderKitFactory = null;
        _elContext = null;
        _exceptionHandler = null;
        _cachedRenderKit = null;
        _cachedRenderKitId = null;
        _separatorChar = null;
        
        // Spec JSF 2 section getAttributes when release is called the attributes map
        // must!!! be cleared! (probably to trigger some clearance methods on possible
        // added entries before nullifying everything)
        if (_attributes != null)
        {
            _attributes.clear();
            _attributes = null;
        }
        
        _released = true;
        FacesContext.setCurrentInstance(null);
    }
441226
public void release() throws IOException {
    for (BufferPool.Buffer b: buffers) {
      PooledBuffers.release(b);
    }

    buffers.clear();
    count = 0;
  }
366616
private void reallocateBuffer(int newCapacity) {

        byte[] newBuffer = new byte[newCapacity];
        System.arraycopy(m_buffer, 0, newBuffer, 0, Math.min(m_size, newCapacity));
        m_buffer = newBuffer;
    }
643652
protected void releasing(ByteBuffer buffer) {
        if (buffer != null && buffer.isDirect()) {
            DirectByteBufferHelper directByteBufferHelper = this.directByteBufferHelper.get();
            if (directByteBufferHelper != null) {
                directByteBufferHelper.releaseDirectByteBuffer(buffer);
            }
        }
    }
247621
static void release(BufferPool.Buffer buff) throws IOException {
    if (buff.buf.length == staticConf.getSmallBufferSize()) {
      smallBufferPool.put(buff);
    } else if (buff.buf.length == staticConf.getMediumBufferSize()) {
      mediumBufferPool.put(buff);
    } else if (buff.buf.length == staticConf.getLargeBufferSize()) {
      largeBufferPool.put(buff);
    }
  }
605164
@Override
    public byte[] getBuffer () {
        synchronized ( this.cache ) {
            byte[] buf;

            if ( this.freeBuffers > 0 ) {
                for ( int i = 0; i < this.cache.length; i++ ) {
                    if ( this.cache[ i ] != null ) {
                        buf = (byte[]) this.cache[ i ];
                        this.cache[ i ] = null;
                        this.freeBuffers--;
                        return buf;
                    }
                }
            }
            return new byte[this.bufferSize];
        }
    }
627420
public function tearDown()
    {
        // Get and clean output buffer.
        $buffer = ob_get_clean();

        // Pop lastest cache key.
        $key = array_pop($this->keys);

        // Put output buffer content, if
        // we don't have cached value.
        if (! $this->cached) {
            $this->cache->put($key, $buffer, $this->getArgument('expire'));

            return $buffer;
        }

        // Return cache value.
        return $this->cache->get($key);
    }
913448
@Override
    protected boolean checkBuffer() throws IOException {
        if (null != this.buffer) {
            if (this.buffer.hasRemaining()) {
                return true;
            }
            this.buffer.release();
            this.buffer = null;
        }
        return setNextBuffer();
    }
782803
public static TempCharBuffer allocate()
  {
    TempCharBuffer next = _freeList.allocate();

    if (next == null)
      return new TempCharBuffer(SIZE);

    next._next = null;

    next._offset = 0;
    next._length = 0;
    next._bufferCount = 0;

    return next;
  }
887142
private void flushBuffer()
            throws IOException
    {
        if (buffer.position() > 0) {
            buffer.flip();
            writeCompressed(buffer);
            buffer.clear();
        }
    }