Returns a temporary buffer of at least the given size
2357
static ByteBuffer getTemporaryDirectBuffer(int size) {
        BufferCache cache = bufferCache.get();
        ByteBuffer buf = cache.get(size);
        if (buf != null) {
            return buf;
        } else {
            // No suitable buffer in the cache so we need to allocate a new
            // one. To avoid the cache growing then we remove the first
            // buffer from the cache and free it.
            if (!cache.isEmpty()) {
                buf = cache.removeFirst();
                free(buf);
            }
            return ByteBuffer.allocateDirect(size);
        }
    }
281482
def read(self, size=None):  # pylint: disable=invalid-name
        """"""
        if size is None or size < 0:
            raise exceptions.NotYetImplementedError(
                'Illegal read of size %s requested on BufferedStream. '
                'Wrapped stream %s is at position %s-%s, '
                '%s bytes remaining.' %
                (size, self.__stream, self.__start_pos, self.__end_pos,
                 self._bytes_remaining))

        data = ''
        if self._bytes_remaining:
            size = min(size, self._bytes_remaining)
            data = self.__buffered_data[
                self.__buffer_pos:self.__buffer_pos + size]
            self.__buffer_pos += size
        return data
1255627
def create_buffer(params, value):
    '''
    
    '''
    try:
        fv = float(value)
        return np.full(params.length, fv, np.float)
    except TypeError:
        if isinstance(value, np.ndarray):
            if (len(value)>=params.length):
                return value
        raise TypeError('Value must be a float or a numpy array ofthe required length')
253891
def read(self, size=-1):
        """"""
        if self.connected is None:
            return None

        # Extract requested amount of data from the read buffer.
        data = self._get_input(size)

        return data
1054843
def _ram_buffer(self):
        """"""
        # get the address of the RAM
        address = _LIB.Memory(self._env)
        # create a buffer from the contents of the address location
        buffer_ = ctypes.cast(address, ctypes.POINTER(RAM_VECTOR)).contents
        # create a NumPy array from the buffer
        return np.frombuffer(buffer_, dtype='uint8')
1350891
def randombytes(size):
    
    buf = ffi.new("unsigned char[]", size)
    lib.randombytes(buf, size)
    return ffi.buffer(buf, size)[:]
134780
private int ensureBuffer(int offset, int length) throws IOException {
		final int lastPos = offset + length - 1;
		final int desiredSize = ((lastPos / BUFFER_SIZE) + 1) * BUFFER_SIZE;
		final int currentSize = this.buffer.length;

		if (desiredSize > currentSize) {
			final byte[] readBuffer = new byte[desiredSize - currentSize];
			final int count = this.in.read(readBuffer);

			if (count > 0) {
				final byte[] newBuffer = new byte[currentSize + count];
				System.arraycopy(this.buffer, 0, newBuffer, 0, currentSize);
				System.arraycopy(readBuffer, 0, newBuffer, currentSize, count);
				this.buffer = newBuffer;
			}
			return (lastPos < this.buffer.length) ? length : length - (lastPos - this.buffer.length + 1);
		}
		return length;
	}
377152
def buffer(self, *args, **kwargs):
        """"""
        self.check_session()
        result = self.session.buffer(*args, **kwargs)
        return result
525353
def read(self, size=None):
        
        if size is None:
            t = []
            while True:
                buf = self._read(self.bufsize)
                if not buf:
                    break
                t.append(buf)
            buf = "".join(t)
        else:
            buf = self._read(size)
        self.pos += len(buf)
        return buf
1351528
static final byte[] resizeBuffer(final byte[] buf, final int newsize) {
		if (buf.length == newsize)
			return buf;
		final byte[] newbuf = new byte[newsize];
		System.arraycopy(buf, 0, newbuf, 0, Math.min(buf.length, newbuf.length));
		return newbuf;
	}
960188
def fixed_length(cls, l, allow_empty=False):
        """"""
        return cls(l, l, allow_empty=allow_empty)
270745
function bnToBuffer(trimOrSize) {
    var res = new Buffer(this.toByteArray());
    if (trimOrSize === true && res[0] === 0) {
        res = res.slice(1);
    } else if (_.isNumber(trimOrSize)) {
        if (res.length > trimOrSize) {
            for (var i = 0; i < res.length - trimOrSize; i++) {
                if (res[i] !== 0) {
                    return null;
                }
            }
            return res.slice(res.length - trimOrSize);
        } else if (res.length < trimOrSize) {
            var padded = new Buffer(trimOrSize);
            padded.fill(0, 0, trimOrSize - res.length);
            res.copy(padded, trimOrSize - res.length);
            return padded;
        }
    }
    return res;
}
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;
}
1126294
public static LinkedBuffer allocate(int size, LinkedBuffer previous)
    {
        if (size < MIN_BUFFER_SIZE)
            throw new IllegalArgumentException(MIN_BUFFER_SIZE + " is the minimum buffer size.");

        return new LinkedBuffer(size, previous);
    }
883232
def __fill_buffer(self, size=0):
    
    read_size = min(max(size, self.__buffer_size), MAX_BLOB_FETCH_SIZE)

    self.__buffer = fetch_data(self.__blob_key, self.__position,
                               self.__position + read_size - 1)
    self.__buffer_position = 0
    self.__eof = len(self.__buffer) < read_size
414303
def write(self, s, size=None):
        
        self._buffer.write(s)
        self._len_changed = True
145025
@SuppressWarnings("unchecked")
    public static ByteBuffer allocateDirectBuffer(int size) {
        try {
            Class<?> cls = Class.forName("java.nio.DirectByteBuffer");
            Constructor<?> constructor = cls.getDeclaredConstructor(Long.TYPE, Integer.TYPE);
            constructor.setAccessible(true);
            Field cleanerField = cls.getDeclaredField("cleaner");
            cleanerField.setAccessible(true);
            final long memory = allocateMemory(size);
            ByteBuffer buffer = (ByteBuffer) constructor.newInstance(memory, size);
            Cleaner cleaner = Cleaner.create(buffer, new Runnable() {
                @Override
                public void run() {
                    freeMemory(memory);
                }
            });
            cleanerField.set(buffer, cleaner);
            return buffer;
        } catch (Exception e) {
            throwException(e);
        }
        throw new IllegalStateException("unreachable");
    }