/** * Construct a new FileReader. * @param mixed $file PhingFile or string pathname. */ public function __construct($file) { $in = new FileInputStream($file); parent::__construct($in); }
/** * Read frame from wire * * @param io.streams.InputStreamReader in */ public function fromWire(InputStreamReader $in) { // Read headers $line = $in->readLine(); while (0 != strlen($line)) { list($key, $value) = explode(':', $line, 2); $this->addHeader($key, $value); // Next line $line = $in->readLine(); } // Now, read payload if ($this->hasHeader('content-length')) { // If content-length is given, read that many bytes as body from // stream and assert that it is followed by a chr(0) byte. $data = $in->read($this->getHeader('content-length')); if ("\n" != $in->read(2)) { throw new ProtocolException('Expected chr(0) and newline after frame w/ given content-length'); } } else { // Read line-wise as we know that \0\n marks the end $data = ''; do { if (NULL === ($line = $in->readLine())) { throw new ProtocolException('Received EOF before payload end delimiter \\0\\n'); } $data .= $line . "\n"; } while ("" !== $line[strlen($line) - 1]); } $this->setBody(rtrim($data, "\n")); }