/** * Returns the next character in the filtered stream. If the desired * number of lines have already been read, the resulting stream is * effectively at an end. Otherwise, the next character from the * underlying stream is read and returned. * * @param int $len * @return int|string the next character in the resulting stream, or -1 * if the end of the resulting stream has been reached * * @throws IOException if the underlying stream throws an IOException * during reading * @throws BuildException */ public function read($len = 0) { // do the "singleton" initialization if (!$this->getInitialized()) { $this->initialize(); $this->setInitialized(true); } $ch = -1; // The readers return -1 if they end. So simply read the "prepend" // after that the "content" and at the end the "append" file. if ($this->prependReader !== null) { $ch = $this->prependReader->read(); if ($ch === -1) { // I am the only one so I have to close the reader $this->prependReader->close(); $this->prependReader = null; } } if ($ch === -1) { $ch = parent::read(); } if ($ch === -1 && $this->appendReader !== null) { $ch = $this->appendReader->read(); if ($ch === -1) { // I am the only one so I have to close the reader $this->appendReader->close(); $this->appendReader = null; } } return $ch; }
/** * set the text using a file * @param file the file to use * @throws BuildException if the file does not exist, or cannot be * read */ public function setFile(PhingFile $file) { // non-existing files are not allowed if (!$file->exists()) { throw new BuildException("File " . $file . " does not exist."); } $reader = null; try { if ($this->encoding == null) { $reader = new BufferedReader(new FileReader($file)); } else { $reader = new BufferedReader(new InputStreamReader(new FileInputStream($file))); } $this->value = $reader->read(); } catch (IOException $ex) { $reader->close(); throw new BuildException($ex); } $reader->close(); }