Introduced isReachableFilePath() and isReadableFile().
[core.git] / inc / classes / main / file_directories / io / class_FrameworkFileInputOutputPointer.php
index 0a750029371e42a9bb173954dd2b0fc728578871..edf9f5728a4dae33058261bed2f3af15fbd3e56d 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -48,12 +48,15 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                if ((is_null($fileName)) || (empty($fileName))) {
                        // No filename given
                        throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif ((file_exists($fileName)) && (!is_readable($fileName))) {
+               } elseif (!BaseFrameworkSystem::isReachableFilePath($fileName)) {
+                       // File exists but cannot be read
+                       throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
+               } elseif (!BaseFrameworkSystem::isReadableFile($fileName)) {
                        // File exists but cannot be read
                        throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
-               } elseif ((file_exists($fileName)) && (!is_writable($fileName))) {
+               } elseif (!is_writable($fileName)) {
                        // File exists but cannot be written
-                       throw new FileWriteProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
+                       throw new FileWriteProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_WRITTEN);
                }
 
                // Try to open a handler
@@ -167,21 +170,34 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                return fseek($this->getPointer(), $seekPosition, $whence);
        }
 
+       /**
+        * Reads a line, maximum 4096 Bytes from current file pointer
+        *
+        * @return      $data   Read data from file
+        */
+       public function readLine () {
+               // Read whole line
+               return $this->read();
+       }
+
        /**
         * Reads given amount of bytes from file.
         *
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
         */
-       public function read ($bytes) {
+       public function read ($bytes = NULL) {
                // Validate the pointer
                $this->validateFilePointer();
 
-               // Try to read given characters
-               $data = fread($this->getPointer(), $bytes);
-
-               // Was this successfull?
-               assert(is_string($data));
+               // Is $bytes set?
+               if (is_int($bytes)) {
+                       // Try to read given characters
+                       $data = fread($this->getPointer(), $bytes);
+               } else {
+                       // Try to read whole line
+                       $data = fread($this->getPointer());
+               }
 
                // Then return it
                return $data;