{@inheritDoc}

@see jcifs.BufferCache#releaseBuffer(byte[])
9489
@Override
    public void releaseBuffer ( byte[] buf ) {
        // better safe than sorry: prevent leaks if there is some out of bound access
        Arrays.fill(buf, (byte) 0);
        synchronized ( this.cache ) {
            if ( this.freeBuffers < this.cache.length ) {
                for ( int i = 0; i < this.cache.length; i++ ) {
                    if ( this.cache[ i ] == null ) {
                        this.cache[ i ] = buf;
                        this.freeBuffers++;
                        return;
                    }
                }
            }
        }
    }
679196
public static ByteBuf wrappedBuffer(byte[] array) {
        if (array.length == 0) {
            return EMPTY_BUFFER;
        }
        return new UnpooledHeapByteBuf(ALLOC, array, array.length);
    }
699411
@Override
    public void close()
            throws IOException
    {
        if (closed) {
            return;
        }
        try {
            flush();
            out.close();
        }
        finally {
            closed = true;
            inputBufferAllocator.release(inputBuffer);
            outputBufferAllocator.release(outputBuffer);
            inputBuffer = null;
            outputBuffer = null;
        }
    }
20654
public synchronized void release()
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "release");

      released = true;
      valid = false;

      if (receivedBuffer != null)
      {
         receivedBuffer.release();
         receivedBuffer = null;
      }
      if (receivedData != null)
      {
         receivedData.release();
         receivedData = null;
      }

      if (dataList != null)
      {
         for (int x = 0; x < dataList.size(); x++)
         {
            dataList.get(x).release();
         }

         dataList.clear();
      }

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "release");
   }
410337
public static void writeBuffer(DataOutput out, ByteBuffer buffer) throws IOException {
        if (buffer.hasArray()) {
            out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
            buffer.position(buffer.limit());
        } else {
            final byte[] array = new byte[buffer.remaining()];
            buffer.get(array);
            assert buffer.remaining() == 0 && buffer.position() == buffer.limit();
            out.write(array);
        }
    }
650425
@Override
    public synchronized void free(Page page) {
        if (page.isFreeable()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Freeing a {}B buffer from chunk {} &{}", DebuggingUtils.toBase2SuffixedString(page.size()), page.index(), page.address());
            }
            markAllAvailable();
            sliceAllocators.get(page.index()).free(page.address(), page.size());
            victims.get(page.index()).remove(page);
            victimAllocators.get(page.index()).tryFree(page.address(), page.size());
            if (!fallingThresholds.isEmpty()) {
              long allocated = getAllocatedSize();
              fireThresholds(allocated + page.size(), allocated);
            }
        }
    }
222931
public void setBuffer(final String buffer) {
        this.buffer = Arrays.copyOf(buffer.getBytes(), Math.max(buffer.length() + 1, MIN_BUFFER_LEN));
        this.bufferLength = this.buffer.length;
    }
83063
public static ByteBuffer toBuffer(byte[] array) {
        if (array == null)
            return EMPTY_BUFFER;
        return toBuffer(array, 0, array.length);
    }
821936
public void release(PooledWsByteBufferImpl buffer) {
        if (inUseTable != null) {
            inUseTable.remove(buffer);
        }
        boolean pooled = pool.put(buffer);
        if (isDirectPool && !pooled) {
            destroy(buffer);
        }
    }
668317
@Override
    public void release() throws IOException
    {
        if (includeLevel.in != null && end != cursor)
        {
            if (end % size < cursor % size)
            {
                buffer2.position(0);
                buffer2.limit((int)(end % size));
                buffer1.position((int)(cursor % size));
                buffer1.limit(size);
            }
            else
            {
                buffer2.position((int)(cursor % size));
                buffer2.limit((int)(end % size));
                buffer1.position(size);
            }
            if (features.contains(UsePushback))
            {
                if (includeLevel.in instanceof Pushbackable)
                {
                    Pushbackable p = (Pushbackable) includeLevel.in;
                    p.pushback(array2);
                }
                else
                {
                    unread(includeLevel.in);
                }
            }
            else
            {
                if (includeLevel.in instanceof Rewindable)
                {
                    Rewindable rewindable = (Rewindable) includeLevel.in;
                    rewindable.rewind((int)(end-cursor));
                }
                else
                {
                    unread(includeLevel.in);
                }
            }
            buffer1.clear();
            buffer2.clear();
            end = cursor;
        }
    }
487842
private static byte[] toByteArray(final ByteBuffer buffer)
  {
    if (buffer.hasArray()
        && buffer.arrayOffset() == 0
        && buffer.position() == 0
        && buffer.array().length == buffer.limit()) {
      return buffer.array();
    } else {
      final byte[] retVal = new byte[buffer.remaining()];
      buffer.duplicate().get(retVal);
      return retVal;
    }
  }
1356847
public void update(ByteBuffer buffer) {
    length += buffer.remaining();
    //Save current position to leave given buffer unchanged
    int position = buffer.position();
    
    //Complete the final buffer if needed
    completeFinalBuffer(buffer);
    
    while(buffer.remaining() >= 64) {
      transform(buffer);
    }
    
    if(buffer.remaining() != 0) {
      finalBuffer.put(buffer);
    }
    
    buffer.position(position);
  }
614255
public void releaseCache() {
        if (originalThunks != null) {
            // OPTIMIZATION:
            // Rather than use the standard iterator, which creates lots of int[] arrays on the heap, which need to be GC'd,
            // we use the fast version that just mutates one array. Since this is read once for us here, this is ideal.
            Iterator<int[]> fastPassByReferenceIterator = fastPassByReferenceIterator();
            int[] assignment = fastPassByReferenceIterator.next();
            while (true) {
                setAssignmentValue(assignment, originalThunks.getAssignmentValue(assignment));

                // Set the assignment arrays correctly
                if (fastPassByReferenceIterator.hasNext()) fastPassByReferenceIterator.next();
                else break;
            }
            // Release our replicated set of original thunks
            originalThunks = null;
        }
    }
840443
@Override
	public void release() {
		super.release();
		setTypeExpr(null);
		setSrcExpr(null);
		setUseRandomParamExpr(null);
		setAsyncExpr(null);
		setDeferExpr(null);
	}
722178
public synchronized byte[] getBufferBytes() {
        byte[] dest = new byte[count];
        System.arraycopy(buf, 0, dest, 0, dest.length);
        return dest;
    }
821871
@Override
  public byte []nextBuffer(int offset)
    throws IOException
  {
    if (offset < 0 || SIZE < offset) {
      throw new IllegalStateException(L.l("Invalid offset: " + offset));
    }
    
    if (_bufferCapacity <= SIZE
        || _bufferCapacity <= offset + _bufferSize) {
      _offset = offset;
      flushByteBuffer();

      return buffer();
    }
    else {
      _tBuf.length(offset);
      _bufferSize += offset;

      TempBuffer tempBuf = TempBuffer.create();
      _tBuf.next(tempBuf);
      _tBuf = tempBuf;

      _buffer = _tBuf.buffer();
      _offset = _startOffset;

      return _buffer;
    }
  }
890070
@Override
    public WsByteBuffer wrap(byte[] array) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "wrap");
        }

        WsByteBufferImpl buffer = new WsByteBufferImpl();
        buffer.setByteBuffer(ByteBuffer.wrap(array));

        buffer.setPoolManagerRef(this);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "wrap");
        }
        return (buffer);
    }