Allocate the buffer size we need and then pre-configure the buffer to prepare it to be read into
Once it has been prepared set the buffer to the TCP Channel
173669
private void setAndAllocateBuffer(int sizeToAllocate) {
        
        if(_buffer == null){
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
                Tr.debug(tc, "setAndAllocateBuffer, Buffer is null, size to allocate is : " + sizeToAllocate);
            }
            _buffer = allocateBuffer(sizeToAllocate);
        }
        
        configurePreReadBuffer(sizeToAllocate);
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
          Tr.debug(tc, "setAndAllocateBuffer, Setting the buffer : " + _buffer );         
        }
        
        _tcpContext.getReadInterface().setBuffer(_buffer);
    }
1219917
def trace_set_buffer_capacity(self, size):
        
        cmd = enums.JLinkTraceCommand.SET_CAPACITY
        data = ctypes.c_uint32(size)
        res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(data))
        if (res == 1):
            raise errors.JLinkException('Failed to set trace buffer size.')
        return None
45444
public void configurePostInitialReadBuffer(){
        _isInitialRead = false;
        _isFirstRead = false;
        _buffer = _tcpContext.getReadInterface().getBuffer();
        configurePostReadBuffer();
    }
1234468
private void prepSocketChannel(SocketChannel sc) {
        try {
            sc.socket().setSendBufferSize(1024 * 1024 * 2);
            sc.socket().setReceiveBufferSize(1024 * 1024 * 2);
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
1206224
function allocBuffer(size) {
    if (typeof size !== 'number') {
        throw new Error('size passed to allocBuffer must be a number.');
    }
    var buffer = typeof Buffer.alloc === 'function' ? Buffer.alloc(size) : new Buffer(size);
    buffer.fill(0);
    return buffer;
}
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;
    }
52754
public void init(SocketChannel s)
  {
    _s = s;

    try {
      s.setOption(StandardSocketOptions.TCP_NODELAY, true);
    } catch (Exception e) {
      e.printStackTrace();;
    }
    //_is = null;
    //_os = null;
    _needsFlush = false;
    
    _readBuffer.clear().flip();
    _writeBuffer.clear();
  }
278097
protected ByteBuffer allocateBuffer() {
		if (_buffersToReuse != null && !_buffersToReuse.isEmpty()) {
			ByteBuffer bb = _buffersToReuse.poll();
			bb.rewind();
			bb.limit(bb.capacity());
			return bb;
		}
		ByteBuffer r = StaticBuffers.getInstance().byteBuffer(BUFFER_KEY, _bufferSize);
		r.limit(_bufferSize);
		return r.order(_order);
	}
425627
@Override
    public void setBufferSize(int size) {
        if (this.writing || isClosed()) {
            throw new IllegalStateException("Stream unable to set size");
        }
        this.amountToBuffer = size;
        this.bbSize = (49152 < size) ? 32768 : 8192;

        // make sure we never create larger frames than the max http2 frame size
        Integer h2size = (Integer) this.getVc().getStateMap().get("h2_frame_size");
        if (h2size != null && h2size < bbSize) {
            this.bbSize = h2size;
        }

        int numBuffers = (size / this.bbSize);
        if (0 == size || 0 != (size % this.bbSize)) {
            numBuffers++;
        }
        this.output = new WsByteBuffer[numBuffers];
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "setBufferSize=" + size + "; " + this);
        }
    }
71807
static void fillBufferFrom(InputStream in, byte[] buf, int offset, int len)
            throws IOException
    {
        for (int read = 0; len > 0; len -= read, offset += read)
        {
            read = in.read(buf, offset, len);
            if (read == -1)
                throw ProtobufException.truncatedMessage();
        }
    }
791436
public WsByteBuffer allocateBuffer(int size) {
        WsByteBufferPoolManager mgr = HttpDispatcher.getBufferManager();
        WsByteBuffer wsbb = (this.useDirectBuffer) ? mgr.allocateDirect(size) : mgr.allocate(size);
        addToCreatedBuffer(wsbb);
        return wsbb;
    }
724064
private void buffer() throws IOException {
        int remaining = buffer.length;
        while (remaining > 0) {
            int r = input.read(buffer, buffer.length - remaining, remaining);
            if (r <= 0) {
                // Not enough information to fill the buffer
                offset = 0;
                maxOffset = buffer.length - remaining;
                return;
            }
            remaining -= r;
        }
        maxOffset = buffer.length;
        offset = 0;
    }
1134689
def buffer(msg, opts)
      buffer_size = write_to_buffer(msg, opts)
      unless buffer_size.nil?
        process_buffer(buffer_size)
      end
    end
1067078
def read_into_buffer(buffer, size)
      tmp = read_all(size)
      i = 0
      tmp.each_byte do |byte|
        Bytes.set_string_byte(buffer, i, byte)
        i += 1
      end
      i
    end
857109
private void expandBuffer(int newBufferSize)
    {
        // Allocate a new buffer.
        ByteBuffer newBuffer = ByteBuffer.allocate(newBufferSize);

        // Copy the content of the current buffer to the new buffer.
        int oldPosition = mBuffer.position();
        mBuffer.position(0);
        newBuffer.put(mBuffer);
        newBuffer.position(oldPosition);

        // Replace the buffers.
        mBuffer = newBuffer;
    }
769232
def _read_until(cls, sock, desired_size):
    """"""
    buf = b''
    while len(buf) < desired_size:
      recv_bytes = sock.recv(desired_size - len(buf))
      if not recv_bytes:
        raise cls.TruncatedRead('Expected {} bytes before socket shutdown, instead received {}'
                                .format(desired_size, len(buf)))
      buf += recv_bytes
    return buf
1315
def set_buffer_limits(self, high=None, low=None):
        """"""
        if high is None:
            high = self.default_buffer_size
        if low is None:
            low = high // 2
        self._buffer_high = high
        self._buffer_low = low