home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / system / io / FileInputStream.php < prev    next >
Encoding:
PHP Script  |  2007-08-28  |  2.4 KB  |  77 lines

  1. <?php
  2. /*
  3.  *  $Id: FileWriter.php 123 2006-09-14 20:19:08Z mrook $  
  4.  * 
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information please see
  19.  * <http://phing.info>.
  20.  */
  21.  
  22. require_once 'phing/system/io/InputStream.php';
  23. require_once 'phing/system/io/PhingFile.php';
  24.  
  25. /**
  26.  * Input stream subclass for file streams.
  27.  * 
  28.  * @package   phing.system.io
  29.  */
  30. class FileInputStream extends InputStream {
  31.     
  32.     /**
  33.      * @var PhingFile The associated file.
  34.      */
  35.     protected $file;
  36.     
  37.     /**
  38.      * Construct a new FileInputStream.
  39.      * @param mixed $file
  40.      * @throws Exception - if invalid argument specified.
  41.      * @throws IOException - if unable to open file.
  42.      */
  43.     public function __construct($file, $append = false) {
  44.         if ($file instanceof PhingFile) {
  45.             $this->file = $file;
  46.         } elseif (is_string($file)) {
  47.             $this->file = new PhingFile($file);
  48.         } else {
  49.             throw new Exception("Invalid argument type for \$file.");
  50.         }
  51.         
  52.         $stream = @fopen($this->file->getAbsolutePath(), "rb");
  53.         if ($stream === false) {
  54.             throw new IOException("Unable to open " . $this->file->__toString() . " for reading: " . $php_errormsg);
  55.         }
  56.         
  57.         parent::__construct($stream);
  58.     }
  59.     
  60.     /**
  61.      * Returns a string representation of the attached file.
  62.      * @return string
  63.      */
  64.     public function __toString() {
  65.         return $this->file->getPath();
  66.     }
  67.     
  68.     /**
  69.      * Mark is supported by FileInputStream.
  70.      * @return boolean TRUE
  71.      */
  72.     public function markSupported() {
  73.         return true;
  74.     }
  75. }
  76.  
  77.