Read

@param int $length number of bytes
@return string data read

@throws RuntimeException
542469
public final function read($length): string
   {
       if (!$this->isReadable()) {
           throw new RuntimeException("Can't read: stream is not readable");
       }
       $read = (string) fread($this->stream, (int) $length);
       $this->meta["eof"] = !$read ? true : false;
       return $read;
   }
982267
protected function _read($length)
    {
        $result = fread($this->_fileHandler, $length);

        if (false === $result) {
            throw new Mage_Exception('Failed to read data from ' . $this->_filePath);
        }

        return $result;
    }
976860
public static function randomBytes($length = 16)
    {
        if (function_exists('random_bytes')) {
            $bytes = random_bytes($length);
        } elseif (function_exists('openssl_random_pseudo_bytes')) {
            $bytes = openssl_random_pseudo_bytes($length, $strong);
            if (false === $bytes || false === $strong) {
                throw new RuntimeException('Unable to generate random string.');
            }
        } else {
            throw new RuntimeException('OpenSSL extension is required for PHP 5 users.');
        }

        return $bytes;
    }
922848
public static function readString(&$buffer)
    {
        $tmp = unpack('n', $buffer);
        $length = array_pop($tmp);
        if ($length + 2 > strlen($buffer)) {
            throw new \RuntimeException("buffer:".bin2hex($buffer)." lenth:$length not enough for unpackString");
        }

        $string = substr($buffer, 2, $length);
        $buffer = substr($buffer, $length + 2);
        return $string;
    }
1039219
public function seekAndRead($length)
    {
        $this->stream->seek($this->offset + $this->position);
        if ($this->limit !== -1) {
            $length = min($length, $this->limit - $this->position);
            if ($length <= 0) {
                return '';
            }
        }
        return $this->stream->read($length);
    }
119774
public function read(int $length = 8192): string
    {
        $bytes           = substr($this->buffer, $this->position, $length);
        $this->position += strlen($bytes);
        return $bytes;
    }
221296
public function writeStream(Stream $stream, $length)
    {
        $target  = $this->stream;
        $source  = $stream->stream;
        $written = stream_copy_to_stream($source, $target);

        if ($written !== $length) {
            throw new RuntimeException('Failed to write stream with ' . $length . ' bytes');
        }

        $this->size = null;

        return $written;
    }
859570
public function read($length)
    {
        $buffer = $this->socket->read($length);

        if ($this->state < self::STATE_OPEN) {
            $this->handshakeBuffer .= $buffer;

            $headerPos = mb_strpos(
                $this->handshakeBuffer,
                "\r\n\r\n",
                0,
                '8bit'
            );

            if ($headerPos !== false) {
                $data = mb_substr(
                    $this->handshakeBuffer,
                    0,
                    $headerPos,
                    '8bit'
                );

                try {
                    $this->handleHandshake($data);
                } catch (Net_Notifier_WebSocket_ProtocolException $e) {
                    $this->state = self::STATE_CLOSED;
                    $this->shutdown();
                }

                $length = mb_strlen($this->handshakeBuffer, '8bit');
                $buffer = mb_substr(
                    $this->handshakeBuffer,
                    $headerPos + 4,
                    $length - $headerPos - 5,
                    '8bit'
                );
            }
        }

        if ($this->state > self::STATE_CONNECTING) {
            $frames = $this->parser->parse($buffer);

            foreach ($frames as $frame) {
                $this->handleFrame($frame);
            }
        }

        return (
               count($this->textMessages) > 0
            || count($this->binaryMessages) > 0
        );
    }
1170666
public function stream_read($length)
    {
        if ($this->fileHandle === null) {
            return false;
        }
        self::restore();
        $content = fread($this->fileHandle, $length);
        self::register();
        return $content;
    }
212971
private static function read($fd, $length)
    {
        $bytes = fread($fd, $length);
        if (false === $bytes) {
            return false;
        }

        return $bytes;
    }
592515
public static function read($source, $length = 0)
    {
        if (!is_file($source) || !is_readable($source)) {
            return false;
        }
        try {
            if ($length <= 0 || $length > filesize($source)) {
                return file_get_contents($source);
            }

            $file = @fopen($source, 'r');
            $content = @fread($file, $length);
            @fclose($file);
            return $content;
        } catch (\Exception $e) {
            return false;
        }
    }
1110934
private function socketRead($length)
    {
        $read = '';

        do {
            $read .= \fread($this->socket, $length - \strlen($read));
        } while (\strlen($read) < $length && !\feof($this->socket));

        return $read;
    }
818674
final protected function fread($length = null)
	{
		if (! is_int($length)) {
			$length = $this->fstat('size');
		}
		return fread($this->fhandle, $length);
	}
979454
public function readBinary(int $length = 1024): string
    {
        $data = fread($this->resource, $length);
        if (false === $data) {
            if (stream_get_meta_data($this->resource)['timed_out']) {
                throw new Timeout(
                        'Reading of ' . $length . ' bytes failed: timeout of '
                        . $this->timeout . ' seconds exceeded'
                );
            }

            throw new ConnectionFailure(
                    'Reading of ' . $length . ' bytes failed.'
            );
        }

        return $data;
    }
604866
public function generateRandomString(int $length = 32): string
    {
        if ($length < 1) {
            throw new \RuntimeException('First parameter ($length) must be greater than 0');
        }

        $bytes = $this->generateRandomKey($length);
        return \substr(StringHelper::base64UrlEncode($bytes), 0, $length);
    }
1012027
public function read($length)
    {
        if ($this->isOpen() === false) {
            $msg = "Cannot read from a closed MemoryStream.";
            throw new MemoryStreamAccess($msg, $this, MemoryStreamException::NOT_OPEN);
        }
        
        if ($length === 0) {
            return '';
        }

        $position = $this->position;
        $finalPosition = $position + $length;

        if ($finalPosition > $this->length) {
            $msg = "Cannot read outside the bounds of the MemoryStream.";
            throw new MemoryStreamException($msg, $this, MemoryStreamException::READ);
        }

        $this->incrementPosition($length);

        $returnValue = '';

        while ($position < $finalPosition) {
            $returnValue .= $this->binary[$position];
            $position++;
        }

        return $returnValue;
    }
263908
public function read($length = null) {
		if (isset($length)) {
			return substr($this->str, 0, $length);
		}
		return $this->str;	
	}