]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/file_directories/class_BaseFileIo.php
Rewrites:
[core.git] / framework / main / classes / file_directories / class_BaseFileIo.php
index 4a024c8db034886df850e49137ebef9bb3ff6bce..71d6d3ba60498db84cb3216fd63f83a35cdacbd0 100644 (file)
@@ -9,6 +9,7 @@ use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SplFileObject;
 
 /**
@@ -76,7 +77,7 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
         */
        public function closeFile () {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileObject()->getPathname()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: fileName=%s - CALLED!', $this->getFileObject()->getPathname()));
 
                if (is_null($this->getFileObject())) {
                        // Pointer not initialized
@@ -87,13 +88,13 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
                }
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: Closing file %s ...', __METHOD__, __LINE__, $this->getFileObject()->getPathname()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: Closing file %s ...', $this->getFileObject()->getPathname()));
 
                // Close the file pointer by NULL-ing it
                $this->resetFileObject();
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: EXIT!'));
        }
 
        /**
@@ -151,11 +152,18 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         */
        public function seek (int $offset, int $whence = SEEK_SET) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: offset=%d,whence=%d - CALLED!', $offset, $whence));
+               if ($offset < 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('offset=%d is not valid', $offset));
+               }
+
                // Seek to position
                $status = $this->getFileObject()->fseek($offset, $whence);
 
                // Return status
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] status=%d', __METHOD__, __LINE__, $status));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: status=%d - EXIT!', $status));
                return $status;
        }
 
@@ -167,21 +175,21 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
         */
        public function size () {
                // Get current seek position
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-IO: CALLED!');
                $seekPosition = $this->determineSeekPosition();
 
                // Seek to end
                $seekStatus = $this->seek(0, SEEK_END);
 
                // Get position again (which is the end of the file)
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] seekStatus=%d', __METHOD__, __LINE__, $seekStatus));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: seekStatus=%d', $seekStatus));
                $size = $this->determineSeekPosition();
 
                // Reset seek position to old
                $this->seek($seekPosition);
 
                // Return size
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] size=%s - EXIT!', __METHOD__, __LINE__, $size));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: size=%s - EXIT!', $size));
                return $size;
        }