Changeset 1755

Show
Ignore:
Timestamp:
07/31/08 17:24:46 (4 months ago)
Author:
prema
Message:

Implement enhancement #161

  • EOF - end of file lookup
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework/trunk/src/main/php/net/stubbles/streams/stubInputStream.php

    r1552 r1755  
    3939 
    4040    /** 
     41     * returns true if the stream pointer is at EOF 
     42     * 
     43     * @return  bool 
     44     */ 
     45    public function eof(); 
     46 
     47    /** 
    4148     * closes the stream 
    4249     */ 
  • framework/trunk/src/main/php/net/stubbles/streams/stubResourceInputStream.php

    r1622 r1755  
    3838            throw new stubIllegalArgumentException('Handle needs to be a stream resource.'); 
    3939        } 
    40          
     40 
    4141        $this->handle = $handle; 
    4242    } 
     
    5555            throw new stubIllegalStateException('Can not read from closed input stream.'); 
    5656        } 
    57          
     57 
    5858        $data = @fread($this->handle, $length); 
    5959        if (false === $data) { 
    6060            throw new stubIOException('Can not read from input stream.'); 
    6161        } 
    62          
     62 
    6363        return $data; 
    6464    } 
     
    7777            throw new stubIllegalStateException('Can not read from closed input stream.'); 
    7878        } 
    79          
     79 
    8080        $data = @fgets($this->handle, $length); 
    8181        if (false === $data) { 
    8282            throw new stubIOException('Can not read from input stream.'); 
    8383        } 
    84          
     84 
    8585        return rtrim($data, "\r\n"); 
    8686    } 
     
    9797            throw new stubIllegalStateException('Can not read from closed input stream.'); 
    9898        } 
    99          
     99 
    100100        $bytesRead = ftell($this->handle); 
    101101        if (is_int($bytesRead) === false) { 
    102102            return 0; 
    103103        } 
    104          
     104 
    105105        return $this->getResourceLength() - $bytesRead; 
     106    } 
     107 
     108    /** 
     109     * returns true if the stream pointer is at EOF 
     110     * 
     111     * @return  bool 
     112     */ 
     113    public function eof() 
     114    { 
     115        return feof($this->handle); 
    106116    } 
    107117 
  • framework/trunk/src/test/php/net/stubbles/streams/stubResourceInputStreamTestCase.php

    r1703 r1755  
    105105 
    106106    /** 
     107     * check end of file pointer 
     108     * 
     109     * @test 
     110     */ 
     111    public function endOfFile() 
     112    { 
     113        $this->assertFalse($this->resourceInputStream->eof()); 
     114        $this->resourceInputStream->read(); 
     115        $this->assertTrue($this->resourceInputStream->eof()); 
     116    } 
     117 
     118    /** 
    107119     * trying to read fails after resource was closed 
    108120     *