Returns the last n lines of a file.

@param  int $len Num chars to read.
@return mixed The filtered buffer or -1 if EOF.
2623
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->initialize();
            $this->setInitialized(true);
        }

        while (($buffer = $this->in->read($len)) !== -1) {
            // Remove the last "\n" from buffer for
            // prevent explode to add an empty cell at
            // the end of array
            $buffer = trim($buffer, "\n");

            $lines = explode("\n", $buffer);
            $skip = $this->skip > 0 ? $this->skip : 0;

            if (count($lines) >= $this->lines) {
                // Buffer have more (or same) number of lines than needed.
                // Fill lineBuffer with the last "$this->_lines" lasts ones.
                $off = count($lines) - $this->lines;
                if ($skip > 0) {
                    $this->lineBuffer = array_slice($lines, $off - $skip, -$skip);
                } else {
                    $this->lineBuffer = array_slice($lines, $off);
                }
            } else {
                // Some new lines ...
                // Prepare space for insert these new ones
                $this->lineBuffer = array_slice($this->lineBuffer, count($lines) - 1);
                $this->lineBuffer = array_merge($this->lineBuffer, $lines);
            }
        }

        if (empty($this->lineBuffer)) {
            $ret = -1;
        } else {
            $ret = implode("\n", $this->lineBuffer);
            $this->lineBuffer = [];
        }

        return $ret;
    }
948276
protected function pad($string, $len)
    {
        $strlen = $this->strlen($string);
        if ($strlen > $len) return $string;

        $pad = $len - $strlen;
        return $string . str_pad('', $pad, ' ');
    }
105225
public function readFileLine($length = null)
    {
        $this->openFile();
        //gets warning "fgets(): Length parameter must be greater than 0" when parameter is null and is passed to function
        if($length === null)
        {
            $line = fgets($this->getFile());
        }
        else
        {
            $line = fgets($this->getFile(), $length);
        }

        return $line;
    }
715941
public static function randStr($len = 6)
    {
        $chars = str_repeat('0123456789', $len);
        $chars = str_shuffle($chars);
        $str   = substr($chars, 0, $len);
        return $str;
    }
328388
public function read($len)
    {
        $data = @fread($this->handle_, $len);
        if ($data === false || $data === '') {
            $md = stream_get_meta_data($this->handle_);
            if ($md['timed_out']) {
                throw new TTransportException(
                    'THttpClient: timed out reading ' . $len . ' bytes from ' .
                    $this->host_ . ':' . $this->port_ . $this->uri_,
                    TTransportException::TIMED_OUT
                );
            } else {
                throw new TTransportException(
                    'THttpClient: Could not read ' . $len . ' bytes from ' .
                    $this->host_ . ':' . $this->port_ . $this->uri_,
                    TTransportException::UNKNOWN
                );
            }
        }

        return $data;
    }
446406
public function read($len = null)
    {
        $this->_initialize();

        // Process whole text at once.
        $text = null;
        while (($data = $this->in->read($len)) !== -1) {
            $text .= $data;
        }

        // At the end.
        if (null === $text) {
            return -1;
        }

        $this->log(
            "Encoding " . $this->in->getResource() . " from " . $this->getInputEncoding() . " to " . $this->getOutputEncoding(),
            Project::MSG_VERBOSE
        );

        return iconv($this->_inputEncoding, $this->_outputEncoding, $text);
    }
1226463
public function currentLine() {
        if (empty($this->EOF) || $this->char == 0) {
            return 1;
        }
        // Add one to $this->char because we want the number for the next
        // byte to be processed.
        return substr_count($this->data, "\n", 0, min($this->char, $this->EOF)) + 1;
    }
737645
public static function readline(StreamInterface $stream, $maxLength = null, $eol = PHP_EOL)
    {
        $buffer = '';
        $size = 0;
        $negEolLen = -strlen($eol);

        while (!$stream->eof()) {
            if (false === ($byte = $stream->read(1))) {
                return $buffer;
            }
            $buffer .= $byte;
            // Break when a new line is found or the max length - 1 is reached
            if (++$size == $maxLength || substr($buffer, $negEolLen) === $eol) {
                break;
            }
        }

        return $buffer;
    }
1177694
public static function read_line($f, $action = 'read')
    {
        static $last_line = '';
        static $use_last_line = false;
        if ('clear' == $action) {
            $last_line = '';

            return true;
        }
        if ('put-back' == $action) {
            $use_last_line = true;

            return true;
        }
        $line = $use_last_line ? $last_line : fgets($f);
        $line = ("\r\n" == substr($line, -2)) ?
            rtrim($line, "\r\n") . "\n" :
            $line;
        $last_line = $line;
        $use_last_line = false;

        return $line;
    }
782980
public function read($length)
    {
        if ($this->offset == $this->array_size) {
            return false;
        }

        // Don't use array slice
        $arrays = [];
        $end = $length + $this->offset;
        for ($i = $this->offset; $i < $end; ++$i) {
            if (!isset($this->array[$i])) {
                break;
            }
            $arrays[] = $this->array[$i];
        }
        $this->offset += $i - $this->offset; // Limit function calls
        $chars = false;
        foreach ($arrays as $array) {
            $chars .= implode('', array_map('chr', $array));
        }

        return $chars;
    }
383970
public function last($n)
    {
        $last = '';

        if ($n > 0)
        {
            $last = UTF8::substr
            (
                $this->scalarString,
                -$n,
                null,
                $this->encoding
            );
        }

        return $this->newSelf($last);
    }
315344
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->checkAttributes();
            $this->setInitialized(true);
        }

        $buffer = $this->in->read($len);

        if ($buffer === -1 || !function_exists($this->function)) {
            return -1;
        }

        $lines = explode("\n", $buffer);

        $filtered = array_map($this->function, $lines);

        $filtered_buffer = implode("\n", $filtered);

        return $filtered_buffer;
    }
258314
public function read($len)
    {
        if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
            $this->rBuf_ = $this->transport_->read($this->rBufSize_);
        }

        if (TStringFuncFactory::create()->strlen($this->rBuf_) <= $len) {
            $ret = $this->rBuf_;
            $this->rBuf_ = '';

            return $ret;
        }

        $ret = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
        $this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);

        return $ret;
    }
253315
public function read($len = null)
    {
        if (!class_exists('XSLTProcessor')) {
            throw new BuildException("Could not find the XSLTProcessor class. Make sure PHP has been compiled/configured to support XSLT.");
        }

        if ($this->processed === true) {
            return -1; // EOF
        }

        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        // Read XML
        $_xml = null;
        while (($data = $this->in->read($len)) !== -1) {
            $_xml .= $data;
        }

        if ($_xml === null) { // EOF?

            return -1;
        }

        if (empty($_xml)) {
            $this->log("XML file is empty!", Project::MSG_WARN);

            return ''; // return empty string, don't attempt to apply XSLT
        }

        // Read XSLT
        $_xsl = null;
        $br = new BufferedReader(new FileReader($this->xslFile));
        $_xsl = $br->read();

        $this->log(
            "Tranforming XML " . $this->in->getResource() . " using style " . $this->xslFile->getPath(),
            Project::MSG_VERBOSE
        );

        $out = '';
        try {
            $out = $this->process($_xml, $_xsl);
            $this->processed = true;
        } catch (IOException $e) {
            throw new BuildException($e);
        }

        return $out;
    }
768236
public function read($len = null)
    {
        if (!class_exists('DomDocument')) {
            throw new BuildException("Could not find the DomDocument class. Make sure PHP has been compiled/configured to support DOM XML.");
        }

        if ($this->processed === true) {
            return -1; // EOF
        }

        // Read XML
        $_xml = null;
        while (($data = $this->in->read($len)) !== -1) {
            $_xml .= $data;
        }

        if ($_xml === null) { // EOF?

            return -1;
        }

        if (empty($_xml)) {
            $this->log("XML file is empty!", Project::MSG_WARN);

            return '';
        }

        $this->log("Transforming XML " . $this->in->getResource() . " using Xinclude ", Project::MSG_VERBOSE);

        $out = '';
        try {
            $out = $this->process($_xml);
            $this->processed = true;
        } catch (IOException $e) {
            throw new BuildException($e);
        }

        return $out;
    }
1373142
public static function int2bytes($len, $int = 0, $l = false)
    {
        $hexstr = dechex($int);

        if ($len === null) {
            if (strlen($hexstr) % 2) {
                $hexstr = "0" . $hexstr;
            }
        } else {
            $hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr;
        }

        $bytes = strlen($hexstr) / 2;
        $bin   = '';

        for ($i = 0; $i < $bytes; ++$i)
        {
            $bin .= chr(hexdec(substr($hexstr, $i * 2, 2)));
        }

        return $l ? strrev($bin) : $bin;
    }
685427
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $buffer = $this->in->read($len);

        if ($buffer === -1) {
            return -1;
        }

        $lines = explode("\n", $buffer);
        $matched = [];

        $regexpsSize = count($this->_regexps);
        foreach ($lines as $line) {
            for ($i = 0; $i < $regexpsSize; $i++) {
                $regexp = $this->_regexps[$i];
                $re = $regexp->getRegexp($this->getProject());
                $re->setIgnoreCase(!$this->casesensitive);
                $matches = $re->matches($line);
                if (!$matches) {
                    $line = null;
                    break;
                }
            }
            if ($line !== null) {
                $matched[] = $line;
            }
        }
        $filtered_buffer = implode("\n", $matched);

        if ($this->isNegated()) {
            $filtered_buffer = implode("\n", array_diff($lines, $matched));
        }

        return $filtered_buffer;
    }