prepare bytebuffer

@param $size
@param $additional_bytes
@throws \Exception
430498
public function prep($size, $additional_bytes)
    {
        if ($size > $this->minalign) {
            $this->minalign = $size;
        }

        $align_size = ((~($this->bb->capacity() - $this->space + $additional_bytes)) + 1) & ($size - 1);
        while ($this->space < $align_size + $size  + $additional_bytes) {
            $old_buf_size = $this->bb->capacity();
            $this->bb = $this->growByteBuffer($this->bb);
            $this->space += $this->bb->capacity() - $old_buf_size;
        }

        $this->pad($align_size);
    }
866768
public function setChunkSize($size)
    {
        if(static::MODE == 'cli' && is_numeric($size))
        {
            $this->chunkSize = (int)$size;
        }
        elseif(static::MODE == 'web')
        {
            throw new Exception('Chunk size is not supported on web mode');
        }
        else
        {
            throw new Exception("$size is not a valid chunk size");
        }

        return $this;
    }
654568
public void setProtectionBufferSize(int size)
        throws IOException, ServerException {

        if (size <= 0) {
            throw new IllegalArgumentException("size <= 0");
        }

        localServer.setProtectionBufferSize(size);
        try {
            Command cmd = new Command("PBSZ", Integer.toString(size));
            controlChannel.execute(cmd);
        } catch (FTPReplyParseException rpe) {
            throw ServerException.embedFTPReplyParseException(rpe);
        } catch (UnexpectedReplyCodeException urce) {
            throw ServerException.embedUnexpectedReplyCodeException(
                                urce,
                                "Server refused setting protection buffer size");
        }
        this.session.protectionBufferSize = size;
    }
444277
@Override
	// @NotThreadSafe
	protected void ensureCapacity(long capacity) throws IOException {
		long curCapacity = pbuffer.capacity();
		if(curCapacity<capacity) expandCapacity(curCapacity, capacity);
	}
392950
public function setAdditionalData($additionalData) {
        if (is_null($additionalData)) {
            $additionalData = "";
        }
        if (!is_string($additionalData)) {
            throw new \Exception ("Additional Data must be a String");
        }
        $this->additionalData = $additionalData;
    }
786638
public void ensureCapacity (int additionalCapacity) {
		int newCapacity = size + additionalCapacity;
		if (items.length < newCapacity) resize(newCapacity);
	}
292873
public void ensureCapacity (int additionalCapacity) {
		int sizeNeeded = size + additionalCapacity;
		if (sizeNeeded >= threshold) resize(ObjectMap.nextPowerOfTwo((int)(sizeNeeded / loadFactor)));
	}
792875
public function setHeadersLimit($bytes) {
		if($bytes < static::PHP_HEADERS_SIZE) {
			throw new \Exception('Headers limit cannot be less then ' . __CLASS__ . '::PHP_HEADERS_SIZE');
		}
		$bytes -= static::PHP_HEADERS_SIZE;
		$this->headersLimit = $bytes < static::CLIENT_HEADERS_LIMIT ? $bytes : static::CLIENT_HEADERS_LIMIT;
	}
177523
@Override
    public byte[] initSecContext ( byte[] inputBuf, int offset, int len ) throws CIFSException {
        SpnegoToken resp;
        if ( this.completed ) {
            throw new CIFSException("Already complete");
        }
        else if ( len == 0 ) {
            resp = initialToken();
        }
        else {
            resp = negotitate(inputBuf, offset, len);
        }

        if ( resp == null ) {
            return null;
        }
        return resp.toByteArray();
    }
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;
    }
968475
function ByteBuffer(arg) {
    var initial_size;
    if (arg == null) {
        initial_size = 1024 * 1024;
    } else if (typeof arg === "number") {
        initial_size = arg;
    } else if (arg instanceof Uint8Array) {
        this.buffer = arg;
        this.position = 0;  // Overwrite
        return;
    } else {
        // typeof arg -> String
        throw typeof arg + " is invalid parameter type for ByteBuffer constructor";
    }
    // arg is null or number
    this.buffer = new Uint8Array(initial_size);
    this.position = 0;
}
245837
public static function byte_format($size, $dec = 2)
    {
        $a   = array("B", "KB", "MB", "GB", "TB", "PB");
        $pos = 0;
        while ($size >= 1024) {
            $size /= 1024;
            $pos++;
        }
        return round($size, $dec) . " " . $a[$pos];
    }
1357722
public WrappedByteBuffer skip(int size) {
        _autoExpand(size);
        _buf.position(_buf.position() + size);
        return this;
    }
126607
public synchronized void expand(int additionalCapacity) {
        if (additionalCapacity <= 0) {
            throw new IllegalArgumentException();
        }

        synchronized (lock) { // D312598
            final Object[] newBuffer = new Object[buffer.length + additionalCapacity];

            // PK53203 - put() acquires two locks in sequence. First, it acquires
            // the insert lock to update putIndex. Then, it drops the insert lock
            // and acquires the extract lock to update numberOfUsedSlots. As a
            // result, there is a window where putIndex has been updated, but
            // numberOfUsedSlots has not. Consequently, even though we have
            // acquired both locks in this method, we cannot rely on the values in
            // numberOfUsedSlots; we can only rely on putIndex and takeIndex.

            if (putIndex > takeIndex) {
                // The contents of the buffer do not wrap round
                // the end of the array. We can move its contents
                // into the new expanded buffer in one go.

                int used = putIndex - takeIndex;
                System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                putIndex = used;

                // PK53203.1 - If putIndex == takeIndex, then the buffer is either
                // completely full or completely empty. If it is completely full, then
                // we need to copy and adjust putIndex. Otherwise, we need to set
                // putIndex to 0.
            } else if (putIndex != takeIndex || buffer[takeIndex] != null) {
                // The contents of the buffer wrap round the end
                // of the array. We have to perform two copies to
                // move its contents into the new buffer.

                int used = buffer.length - takeIndex;
                System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                System.arraycopy(buffer, 0, newBuffer, used, putIndex);
                putIndex += used;
            } else {
                putIndex = 0;
            }

            // The contents of the buffer now begin at 0 - update the head pointer.

            takeIndex = 0;

            // The buffer's capacity has been increased so update the count of the
            // empty slots to reflect this.
            buffer = newBuffer;
        } // D312598
    }
1298346
public void setBytes(byte[] data, int size) {
        System.arraycopy(data, 0, this.data, 0, data.length);
        this.size = size;
    }
194320
public static byte[] readBytes(ByteBuffer buffer, int offset, int size) {
        final byte[] dest = new byte[size];
        buffer.get(dest, offset, size);
        return dest;
    }
790090
private void prepareToAddBytes(int numBytes) throws IOException {
		if (buffer.remaining() < numBytes) {
			buffer.flip();
			channel.write(buffer);

			int bufferCapacity = Math.max(BUFFER_SIZE, numBytes);
			if (bufferCapacity != buffer.capacity()) {
				ByteOrder order = buffer.order();
				buffer = ByteBuffer.allocate(bufferCapacity);
				buffer.order(order);
			} else {
				buffer.clear();
			}
		}
	}