See also: FilterReader
Author: Yannick Lecaillez (yl@seasonfive.com)
Inheritance: extends BaseFilterReader, implements Parameterizable
 /**
  * Creates a new filtered reader.
  *
  * @param Reader $in
  *            A Reader object providing the underlying stream. Must not be
  *            <code>null</code>.
  */
 public function __construct(Reader $in = null)
 {
     parent::__construct($in);
 }
Exemple #2
0
 /**
  * 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;
 }