Reads an int of data

@access public
@return integer  1 int of data from the socket, or a PEAR_Error if
not connected.
430049
public function readInt()
    {
        if (!is_resource($this->fp)) {
            return $this->raiseError('not connected');
        }

        $buf = @fread($this->fp, 4);

        return (ord($buf[0]) + (ord($buf[1]) << 8) +
            (ord($buf[2]) << 16) + (ord($buf[3]) << 24));
    }
437755
@Override
  public int readInt() throws IOException {
    byte[] intBytes = new byte[4];
    int i = in.read(intBytes);
    if (i < 4) {
      throw new EOFException();
    }
    intBytes[0] = (byte) (intBytes[0] ^ 0x80);

    int value = 0;
    for (int j = 0; j < intBytes.length; ++j) {
      value = (value << 8) + (intBytes[j] & 0xff);
    }
    return value;
  }
515009
public function read($byte_count=null)
    {

        $this->log('read from  socket');
        $buffer = '';

        if(!is_null($byte_count)) {
        //read the specified amount of data
            $buffer .= fgets($this->socket, 1024);
        } else {
        //read all the data
            while (!feof($this->socket)) {
                $buffer .= fgets($this->socket, 1024);
            }
        }


        return $buffer;
    }
926092
public function read()
    {
        // First, read headers only
        $response = '';
        $gotStatus = false;

        while (($line = @fgets($this->socket)) !== false) {
            $gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
            if ($gotStatus) {
                $response .= $line;
                if (rtrim($line) === '') break;
            }
        }

        $this->_checkSocketReadTimeout();

        $statusCode = Zend_Http_Response::extractCode($response);

        // Handle 100 and 101 responses internally by restarting the read again
        if ($statusCode == 100 || $statusCode == 101) return $this->read();

        // Check headers to see what kind of connection / transfer encoding we have
        $headers = Zend_Http_Response::extractHeaders($response);

        /**
         * Responses to HEAD requests and 204 or 304 responses are not expected
         * to have a body - stop reading here
         */
        if ($statusCode == 304 || $statusCode == 204 ||
            $this->method == Zend_Http_Client::HEAD) {

            // Close the connection if requested to do so by the server
            if (isset($headers['connection']) && $headers['connection'] == 'close') {
                $this->close();
            }
            return $response;
        }

        // If we got a 'transfer-encoding: chunked' header
        if (isset($headers['transfer-encoding'])) {

            if (strtolower($headers['transfer-encoding']) == 'chunked') {

                do {
                    $line  = @fgets($this->socket);
                    $this->_checkSocketReadTimeout();

                    $chunk = $line;

                    // Figure out the next chunk size
                    $chunksize = trim($line);
                    if (! ctype_xdigit($chunksize)) {
                        $this->close();

                        throw new Zend_Http_Client_Adapter_Exception('Invalid chunk size "' .
                            $chunksize . '" unable to read chunked body');
                    }

                    // Convert the hexadecimal value to plain integer
                    $chunksize = hexdec($chunksize);

                    // Read next chunk
                    $read_to = ftell($this->socket) + $chunksize;

                    do {
                        $current_pos = ftell($this->socket);
                        if ($current_pos >= $read_to) break;

                        if($this->out_stream) {
                            if(stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
                              $this->_checkSocketReadTimeout();
                              break;
                             }
                        } else {
                            $line = @fread($this->socket, $read_to - $current_pos);
                            if ($line === false || strlen($line) === 0) {
                                $this->_checkSocketReadTimeout();
                                break;
                            }
                                    $chunk .= $line;
                        }
                    } while (! feof($this->socket));

                    $chunk .= @fgets($this->socket);
                    $this->_checkSocketReadTimeout();

                    if(!$this->out_stream) {
                        $response .= $chunk;
                    }
                } while ($chunksize > 0);
            } else {
                $this->close();

                throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' .
                    $headers['transfer-encoding'] . '" transfer encoding');
            }

            // We automatically decode chunked-messages when writing to a stream
            // this means we have to disallow the Zend_Http_Response to do it again
            if ($this->out_stream) {
                $response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $response);
            }
        // Else, if we got the content-length header, read this number of bytes
        } elseif (isset($headers['content-length'])) {

            // If we got more than one Content-Length header (see ZF-9404) use
            // the last value sent
            if (is_array($headers['content-length'])) {
                $contentLength = $headers['content-length'][count($headers['content-length']) - 1];
            } else {
                $contentLength = $headers['content-length'];
            }

            $current_pos = ftell($this->socket);
            $chunk = '';

            for ($read_to = $current_pos + $contentLength;
                 $read_to > $current_pos;
                 $current_pos = ftell($this->socket)) {

                 if($this->out_stream) {
                     if(@stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
                          $this->_checkSocketReadTimeout();
                          break;
                     }
                 } else {
                    $chunk = @fread($this->socket, $read_to - $current_pos);
                    if ($chunk === false || strlen($chunk) === 0) {
                        $this->_checkSocketReadTimeout();
                        break;
                    }

                    $response .= $chunk;
                }

                // Break if the connection ended prematurely
                if (feof($this->socket)) break;
            }

        // Fallback: just read the response until EOF
        } else {

            do {
                if($this->out_stream) {
                    if(@stream_copy_to_stream($this->socket, $this->out_stream) == 0) {
                          $this->_checkSocketReadTimeout();
                          break;
                     }
                }  else {
                    $buff = @fread($this->socket, 8192);
                    if ($buff === false || strlen($buff) === 0) {
                        $this->_checkSocketReadTimeout();
                        break;
                    } else {
                        $response .= $buff;
                    }
                }

            } while (feof($this->socket) === false);

            $this->close();
        }

        // Close the connection if requested to do so by the server
        if (isset($headers['connection']) && $headers['connection'] == 'close') {
            $this->close();
        }

        return $response;
    }
356370
public function read()
    {
        if (!\is_resource($this->stream)) {
            return;
        }

        $this->keepAlive();
        /*
         * The first byte contains the FIN bit, the reserved bits, and the
         * opcode... We're not interested in them. Yet.
         * the second byte contains the mask bit and the payload's length
         */
        $data = $this->readBytes(2);
        $bytes = \unpack('C*', $data);

        if (empty($bytes[2])){
            return;
        }

        $mask = ($bytes[2] & 0b10000000) >> 7;
        $length = $bytes[2] & 0b01111111;

        /*
         * Here is where it is getting tricky :
         *
         * - If the length <= 125, then we do not need to do anything ;
         * - if the length is 126, it means that it is coded over the next 2 bytes ;
         * - if the length is 127, it means that it is coded over the next 8 bytes.
         *
         * But, here's the trick : we cannot interpret a length over 127 if the
         * system does not support 64bits integers (such as Windows, or 32bits
         * processors architectures).
         */
        switch ($length) {
            case 0x7D: // 125
            break;

            case 0x7E: // 126
                $data .= $bytes = $this->readBytes(2);
                $bytes = \unpack('n', $bytes);

                if (empty($bytes[1])) {
                    throw new RuntimeException('Invalid extended packet len');
                }

                $length = $bytes[1];
            break;

            case 0x7F: // 127
                // are (at least) 64 bits not supported by the architecture ?
                if (8 > PHP_INT_SIZE) {
                    throw new DomainException('64 bits unsigned integer are not supported on this architecture');
                }

                /*
                 * As (un)pack does not support unpacking 64bits unsigned
                 * integer, we need to split the data
                 *
                 * {@link http://stackoverflow.com/questions/14405751/pack-and-unpack-64-bit-integer}
                 */
                $data .= $bytes = $this->readBytes(8);
                list($left, $right) = \array_values(\unpack('N2', $bytes));
                $length = $left << 32 | $right;
            break;
        }

        // incorporate the mask key if the mask bit is 1
        if (true === $mask) {
            $data .= $this->readBytes(4);
        }

        $data .= $this->readBytes($length);

        // decode the payload
        return (string) new Decoder($data);
    }
318774
private function readNumber()
    {
        // Open
        if (false === $this->handle = fopen($this->path, 'c+')) {
            throw new RuntimeException("Failed to open file {$this->path}.");
        }
        // Exclusive lock
        if (!flock($this->handle, LOCK_EX)) {
            throw new RuntimeException("Failed to lock file {$this->path}.");
        }

        if (false !== $number = fread($this->handle, 10)) {
            return intval($number);
        }

        return 0;
    }
208807
public function bytesLeft(): int
    {
        if (null === $this->handle || !is_resource($this->handle)) {
            throw new \LogicException('Can not read from closed input stream.');
        }

        $bytesRead = ftell($this->handle);
        if (!is_int($bytesRead)) {
            return 0;
        }

        return $this->getResourceLength() - $bytesRead;
    }
591987
public function read_message()
  {
    $message = "";
    while (true) {
      socket_recv ( $this->socket , $buf , 4 , MSG_WAITALL );
      if ($buf == null)
        return $buf;
      $frame_size = unpack("Nsize", $buf);
      $frame_size = $frame_size["size"];
      if ($frame_size == 0)
        return $message;
      
      socket_recv ( $this->socket , $buf , $frame_size , MSG_WAITALL );
      $message .= $buf;
    }
    
    return $message;
  }
206256
public function remainingBytes(): int
    {
        /** @var array $stat */
        $stat = \fstat($this->fp);
        /** @var int $pos */
        $pos = \ftell($this->fp);
        return (int) (
            PHP_INT_MAX & (
                (int) $stat['size'] - $pos
            )
        );
    }
223773
protected function readInteger()
    {
        if ($this->littleEndian) {
            $result = unpack('Vint', fread($this->file, 4));
        } else {
            $result = unpack('Nint', fread($this->file, 4));
        }

        return $result['int'];
    }
1175299
private function readaixdata()
    {
        if (count($this->_aixdata) === 0) {
            if (CommonFunctions::executeProgram('prtconf', '', $bufr)) {
                $this->_aixdata = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
            }
        }

        return $this->_aixdata;
    }
809800
private int read() {
        int curByte = 0;
        try {
            curByte = rawData.get() & 0xFF;
        } catch (Exception e) {
            header.status = GifDecoder.STATUS_FORMAT_ERROR;
        }
        return curByte;
    }
1023529
private int readInt() throws IOException {
    latestRead = (int)SerializationUtils.readIntegerType(input, WriterImpl.INT_BYTE_SIZE,
                                                         true, input.useVInts());
    return latestRead;
  }
604407
public function readInt() {
            
            $int = $this->readU29();
            // if int and has the sign bit set
            // Check if the integer is an int
            // and is signed
            if (($int & 0x18000000) == 0x18000000) {
                $int ^= 0x1fffffff;
                $int *= -1;
                $int -= 1;
            } else if (($int & 0x10000000) == 0x10000000) {
                // remove the signed flag
                $int &= 0x0fffffff;
            }

            return $int;

        }
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
        );
    }
89175
public function readTinyInt()
    {
        try {
            $bin = $this->getStream()->read(1);

            return ord($bin);
        } catch (StreamException $e) {
            $this->handleStreamException($e, BinaryStreamAccessException::TINYINT);
        }
    }
1194011
function read($inByte = null)
    {
        $this->_assertReadable();

        $inByte = ($inByte === null)
            ?
            (
                ($this->getBuffer() === null) ? -1 : $this->getBuffer()
            )
            : $inByte;

        $stream = $this->resource()->getRHandler();
        $data   = stream_get_contents($stream, $inByte);
        if (false === $data)
            throw new \RuntimeException('Cannot read stream.');

        if (function_exists('mb_strlen'))
            $transCount = mb_strlen($data, '8bit');
        else
            $transCount = strlen($data);

        $this->_resetTransCount($transCount);

        return $data;
    }