]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 5 Dec 2020 23:56:23 +0000 (00:56 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 5 Dec 2020 23:56:23 +0000 (00:56 +0100)
- validated more parameters to avoid bad invocation with invalid values
- int $bytes = NULL was my default, SPL says 0, not NULL as default value
- improved logger messages by adding type and all parameters

Signed-off-by: Roland Häder <roland@mxchange.org>
23 files changed:
framework/main/classes/file_directories/binary/class_BaseBinaryFile.php
framework/main/classes/file_directories/binary/index/class_IndexFile.php
framework/main/classes/file_directories/class_BaseAbstractFile.php
framework/main/classes/file_directories/class_BaseFileIo.php
framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php
framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php
framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php
framework/main/classes/file_directories/io_stream/class_FileIoStream.php
framework/main/classes/file_directories/text/class_BaseTextFile.php
framework/main/classes/file_directories/text/input/csv/class_CsvInputFile.php
framework/main/classes/index/class_BaseIndex.php
framework/main/classes/index/file_stack/class_FileStackIndex.php
framework/main/classes/iterator/file/class_FileIterator.php
framework/main/classes/output/console/class_ConsoleOutput.php
framework/main/classes/output/debug/console/class_DebugConsoleOutput.php
framework/main/classes/output/debug/error/class_DebugErrorLogOutput.php
framework/main/classes/output/debug/web/class_DebugWebOutput.php
framework/main/classes/output/web/class_WebOutput.php
framework/main/classes/stacker/file/class_BaseFileStack.php
framework/main/interfaces/io/class_Streamable.php
framework/main/interfaces/io/pointer/class_InputPointer.php
framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php
framework/main/middleware/io/class_FileIoHandler.php

index 6ba224e416968a8ed0828c160563a0f5077a0687..4ea56c6837080ad6f7aa8242f9e372a12283105d 100644 (file)
@@ -409,15 +409,16 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
        /**
         * Initializes this file class
         *
-        * @param       $infoInstance   An instance of a SplFileInfo class
+        * @param       $fileInfoInstance       An instance of a SplFileInfo class
         * @return      void
         */
-       protected function initFile (SplFileInfo $infoInstance) {
+       protected function initFile (SplFileInfo $fileInfoInstance) {
                // Get a file i/o pointer instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: infoInstance=%s - CALLED!', $infoInstance));
-               $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($infoInstance));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
+               $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileInfoInstance));
 
                // ... and set it here
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting pointerInstance=%s ...', $pointerInstance->__toString()));
                $this->setPointerInstance($pointerInstance);
 
                // Trace message
@@ -431,10 +432,20 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @param       $data                   Data to be written
         * @param       $flushHeader    Whether to flush the header (default: flush)
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
        public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
-               // Write data at given position
+               // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader)));
+               if ($seekPosition < 0) {
+                       // Invalid seek position
+                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+               } elseif (empty($data)) {
+                       // Empty data is invalid, too
+                       throw new InvalidArgumentException('Parameter "data" is empty');
+               }
+
+               // Write data at given position
                $this->getPointerInstance()->writeAtPosition($seekPosition, $data);
 
                // Increment counter
@@ -461,10 +472,17 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         *
         * @param       $length         Length of the block
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
        protected function markCurrentBlockAsEmpty (int $length) {
-               // Get current seek position
+               // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length));
+               if ($length < 1) {
+                       // Length cannot below one
+                       throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
+               }
+
+               // Get current seek position
                $currentPosition = $this->key();
 
                // Now add it as gap entry
@@ -491,12 +509,12 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                if ($this->isFileInitialized()) {
                        // Some bytes has been written, so rewind to start of it.
                        $rewindStatus = $this->rewind();
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('rewindStatus=%s', $rewindStatus));
 
                        // Is the rewind() call successfull?
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: rewindStatus=%d', $rewindStatus));
                        if ($rewindStatus != 1) {
                                // Something bad happened
-                               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Could not rewind().'));
+                               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Could not rewind().');
                        }
 
                        // Read file header
@@ -507,7 +525,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                }
 
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('isInitialized=%d - EXIT!', intval($isInitialized)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized)));
                return $isInitialized;
        }
 
@@ -517,11 +535,10 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      $isInitialized          Whether the file's size is zero
         */
        public function isFileInitialized () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-
                // Get it from iterator which holds the pointer instance. If false is returned
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $fileSize = $this->size();
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileSize=%s', $fileSize));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize=%s', $fileSize));
 
                /*
                 * The returned file size should not be false or NULL as this means
@@ -533,7 +550,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                $isInitialized = ($fileSize > 0);
 
                // Return result
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('isInitialized=%d - EXIT!', intval($isInitialized)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized)));
                return $isInitialized;
        }
 
@@ -543,9 +560,8 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      void
         */
        public function createFileHeader () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-
                // The file's header should not be initialized here
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                assert(!$this->isFileHeaderInitialized());
 
                // Simple flush file header which will create it.
@@ -554,6 +570,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                // Rewind seek position (to beginning of file) and update/flush file header
                $this->rewindUpdateSeekPosition();
 
+               // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
@@ -562,30 +579,32 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         *
         * @param       $type   Type of the file
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is empty
         */
        public function preAllocateFile (string $type) {
                // Is it enabled?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
-                       // Not enabled
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Not pre-allocating file.'));
-
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s - CALLED!', $type));
+               if (empty($type)) {
+                       // Empty type
+                       throw new InvalidArgumentException('Parameter "type" is empty');
+               } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
                        // Don't continue here.
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Not pre-allocating file.'));
                        return;
                }
 
                // Message to user
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Pre-allocating file ...'));
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
 
                // Calculate minimum length for one entry
                $minLengthEntry = $this->getBlockInstance()->calculateMinimumBlockLength();
 
                // Calulcate seek position
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('minLengthEntry=%s', $minLengthEntry));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minLengthEntry=%s', $minLengthEntry));
                $seekPosition = $minLengthEntry * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count');
 
                // Now simply write a NUL there. This will pre-allocate the file.
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('seekPosition=%s', $seekPosition));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
                $this->writeData($seekPosition, chr(0));
 
                // Rewind seek position (to beginning of file) and update/flush file header
@@ -623,7 +642,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
         */
-       public function read (int $bytes = NULL) {
+       public function read (int $bytes = 0) {
                // Call pointer instance
                return $this->getPointerInstance()->read($bytes);
        }
index 6bcf23bbc260c0196b92649ffca65022a05f91f7..c485275fa1e2b7d416280d781dd85668f69d046a 100644 (file)
@@ -52,7 +52,7 @@ class IndexFile extends BaseBinaryFile implements Block {
         */
        public final static function createIndexFile (SplFileInfo $fileInfoInstance, Block $blockInstance) {
                // Get a new instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance=%s,blockInstance=%s - CALLED!', $fileInfoInstance, $blockInstance->__toString()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,blockInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $blockInstance->__toString()));
                $fileInstance = new IndexFile();
 
                // Set block instance here for callbacks
index 171ad3b73da0be451b94d90f63e53ea5f5e3c054..f72d77534ef29c4fcea109b8c3b4548488dd54de 100644 (file)
@@ -150,6 +150,14 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
                return $this->getPointerInstance()->getFileObject();
        }
 
+       /**
+        * Getter for file's name
+        */
+       public final function getFilename () {
+               // Invole file object's method
+               return $this->getFileObject()->getFilename();
+       }
+
        /**
         * Close a file source and set it's instance to null and the file name
         * to empty
@@ -157,14 +165,12 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         * @return      void
         */
        public function closeFile () {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
-
                // Close down pointer instance as well by unsetting it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: CALLED!');
                $this->unsetPointerInstance();
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__));
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: EXIT!');
        }
 
        /**
index 6e95edd04298a683e1f6d1606c1481ff65651c9c..54ab1dbfc9de8fef64687649b61e10f27735320f 100644 (file)
@@ -150,7 +150,7 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
         * @param       $whence         Added to offset (default: only use offset to seek to)
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                // Seek to position
                $status = $this->getFileObject()->fseek($offset, $whence);
 
index 0a8b447e52d0b5e1558c859bf8e59bcd597ffe7f..5e3c658ead37ac0cc59cfbce2cdd9050c483f7a3 100644 (file)
@@ -125,7 +125,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer {
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
         */
-       public function read (int $bytes = NULL) {
+       public function read (int $bytes = 0) {
                // Try to read given characters
                $data = $this->getFileObject()->fread($bytes);
 
index 642e555fef2a9d2454019e0875ed2668b5c1d1af..20e127f26edeaab359200f616a0c11e26e0e817a 100644 (file)
@@ -120,7 +120,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer {
         * @throws      NullPointerException    If the file pointer instance is not set by setFileObject()
         * @throws      InvalidResourceException        If there is no object being set
         */
-       public function read (int $bytes = NULL) {
+       public function read (int $bytes = 0) {
                // Some sanity checks
                if (is_null($this->getFileObject())) {
                        // Pointer not initialized
@@ -131,7 +131,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer {
                }
 
                // Is $bytes set?
-               if (is_int($bytes)) {
+               if ($bytes > 0) {
                        // Try to read given characters
                        $data = $this->getFileObject()->fread($bytes);
                } else {
index b67025c31edb4c1698780a53df33743119266ee2..61db8a66047a4fabdb099149e9be5da691aa4591 100644 (file)
@@ -13,7 +13,9 @@ use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SplFileInfo;
+use \UnexpectedValueException;
 
 /**
  * A class for reading files
@@ -82,7 +84,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                if ((is_null($fileObject)) || ($fileObject === false)) {
                        // Something bad happend
                        throw new FileIoException($fileInstance->getPathname(), self::EXCEPTION_FILE_POINTER_INVALID);
-               } // END - if
+               }
 
                // Create new instance
                $pointerInstance = new FrameworkFileInputOutputPointer();
@@ -94,36 +96,14 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                return $pointerInstance;
        }
 
-       /**
-        * Validates file pointer and throws exceptions. This method does not return
-        * anything (not reliable) as this method checks the file pointer and on
-        * case of an error it throws an exception. If this method does not throw
-        * any exceptions, the file pointer seems to be fine.
-        *
-        * @return      void
-        * @throws      NullPointerException    If the file pointer instance
-        *                                                                      is not set by setFileObject()
-        * @todo Add more checks
-        */
-       private function validateFilePointer () {
-               if (is_null($this->getFileObject())) {
-                       // Pointer not initialized
-                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
-               } // END - if
-
-               // All fine here
-       }
-
        /**
         * Read 1024 bytes data from a file pointer
         *
         * @return      mixed   The result of fread()
         */
        public function readFromFile () {
-               // Validate the pointer
-               $this->validateFilePointer();
-
                // Read data from the file pointer and return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
                return $this->read(1024);
        }
 
@@ -134,26 +114,52 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         * @return      mixed                   Number of writes bytes or false on error
         */
        public function writeToFile (string $dataStream) {
-               // Validate the pointer
-               $this->validateFilePointer();
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: dataStream(%d)=%s - CALLED!', strlen($dataStream), $dataStream));
+               if (empty($dataStream)) {
+                       // Empty dataStream
+                       throw new InvalidArgumentException('Parameter "dataStream" is empty');
+               }
 
                // Write data to the file pointer and return written bytes
-               return $this->getFileObject()->fwrite($dataStream, strlen($dataStream));
+               $status = $this->getFileObject()->fwrite($dataStream, strlen($dataStream));
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status));
+               return $status;
        }
 
        /**
         * Writes at given position by seeking to it.
         *
         * @param       $seekPosition   Seek position in file
-        * @param       $data                   Data to be written
+        * @param       $dataStream             Data to be written
         * @return      mixed                   Number of writes bytes or false on error
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function writeAtPosition (int $seekPosition, string $data) {
+       public function writeAtPosition (int $seekPosition, string $dataStream) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream()=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
+               if ($seekPosition < 0) {
+                       // Invalid seek position
+                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+               } elseif (empty($dataStream)) {
+                       // Empty dataStream
+                       throw new InvalidArgumentException('Parameter "dataStream" is empty');
+               }
+
                // First seek to it
-               $this->seek($seekPosition);
+               if (!$this->seek($seekPosition)) {
+                       // Could not seek
+                       throw new InvalidArgumentException(sprintf('Could not seek to seekPosition=%d', $seekPosition));
+               }
 
                // Then write the data at that position
-               return $this->writeToFile($data);
+               $status = $this->writeToFile($dataStream);
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status));
+               return $status;
        }
 
        /**
@@ -162,10 +168,8 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         * @return      $status         Status of this operation
         */
        public function rewind () {
-               // Validate the pointer
-               $this->validateFilePointer();
-
                // Rewind the pointer
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
                return $this->getFileObject()->rewind();
        }
 
@@ -175,13 +179,22 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         * @param       $seekPosition   Seek position in file
         * @param       $whence                 "Seek mode" (see http://de.php.net/fseek)
         * @return      $status                 Status of this operation
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function seek ($seekPosition, $whence = SEEK_SET) {
-               // Validate the pointer
-               $this->validateFilePointer();
+       public function seek (int $seekPosition, int $whence = SEEK_SET) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
+               if ($seekPosition < 0) {
+                       // Invalid seek position
+                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+               }
 
                // Move the file pointer
-               return $this->getFileObject()->fseek($seekPosition, $whence);
+               $status = $this->getFileObject()->fseek($seekPosition, $whence);
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status));
+               return $status;
        }
 
        /**
@@ -191,6 +204,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         */
        public function readLine () {
                // Read whole line
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
                return $this->read();
        }
 
@@ -199,13 +213,18 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         *
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
-       public function read (int $bytes = NULL) {
-               // Validate the pointer
-               $this->validateFilePointer();
+       public function read (int $bytes = 0) {
+               // Validatre parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: bytes=%d - CALLED!', $bytes));
+               if ($bytes < 0) {
+                       // Bytes cannot be lesser than zero
+                       throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+               }
 
                // Is $bytes set?
-               if (is_int($bytes)) {
+               if ($bytes > 0) {
                        // Try to read given characters
                        $data = $this->getFileObject()->fread($bytes);
                } else {
@@ -214,6 +233,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                }
 
                // Then return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%s - EXIT!', gettype($data), $data));
                return $data;
        }
 
@@ -264,18 +284,21 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         * "Getter" for file size
         *
         * @return      $fileSize       Size of currently loaded file
+        * @throws      UnexpectedValueException        If $fileData does not contain "size"
         */
        public function getFileSize () {
-               // Check if the pointer is still valid
-               $this->validateFilePointer();
-
                // Get file's data
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
                $fileData = $this->getFileObject()->fstat();
 
                // Make sure the required array key is there
-               assert(isset($fileData['size']));
+               if (!isset($fileData['size'])) {
+                       // Not valid array
+                       throw new UnexpectedValueException(sprintf('fileData=%s has no element "size"', print_r($fileData, TRUE)));
+               }
 
                // Return size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: fileData[size]=%d - EXIT!', $fileData['size']);
                return $fileData['size'];
        }
 
index 1dfc59ce8d97d519f4ee58530b5960e34d2651d8..d547e234bc86588f303b0be180a8e4b82b2d8f6e 100644 (file)
@@ -289,7 +289,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
         * @param       $whence         Added to offset (default: only use offset to seek to)
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                $this->partialStub('offset=' . $offset . ',whence=' . $whence);
        }
 
index 901b70b379975a5b0a4bb835cfc601b1b748d661..44e100b5a742742cc04106f2c0b287c813abc8cc 100644 (file)
@@ -60,7 +60,7 @@ abstract class BaseTextFile extends BaseAbstractFile {
         * @param       $whence         Added to offset (default: only use offset to seek to)
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                // Not possible in text files
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEXT-FILE: offset=' . $offset . ',whence=' . $whence);
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
index d4c84ae6d508d2582a480dee63eac221c32d18b8..66fe6ed1dc0e7ac71a83f688c88b20d83c2bd228 100644 (file)
@@ -68,22 +68,16 @@ class CsvInputFile extends BaseInputTextFile implements CsvInputStreamer {
         * @return      $lineArray                      An indexed array with the read line
         */
        public function readCsvFileLine (string $columnSeparator) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] columnSeparator=%s - CALLED!', __METHOD__, __LINE__, $columnSeparator));
-
                // Read raw line
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] columnSeparator=%s - CALLED!', __METHOD__, __LINE__, $columnSeparator));
                $data = $this->getPointerInstance()->readLine();
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d', __METHOD__, __LINE__, strlen($data)));
-
                // Parse data
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d', __METHOD__, __LINE__, strlen($data)));
                $lineArray = $this->parseDataToIndexedArray($data, $columnSeparator);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] lineArray()=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] lineArray()=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
                return $lineArray;
        }
 
@@ -95,10 +89,8 @@ class CsvInputFile extends BaseInputTextFile implements CsvInputStreamer {
         * @return      $lineArray                      An indexed array with the read line
         */
        private function parseDataToIndexedArray (string $data, string $columnSeparator) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d,columnSeparator=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $columnSeparator));
-
                // Init return array
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d,columnSeparator=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $columnSeparator));
                $lineArray = [];
 
                // Whether the parser reads a quoted string (which may contain the column separator again)
@@ -112,65 +104,49 @@ class CsvInputFile extends BaseInputTextFile implements CsvInputStreamer {
                        // "Cache" char
                        $char = substr($data, $idx, 1);
 
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] idx=%s,char=%s ...', __METHOD__, __LINE__, $idx, $char));
-
                        // Is the column separator found and not within quotes?
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] idx=%d,char=%s ...', __METHOD__, __LINE__, $idx, $char));
                        if (($isInQuotes === false) && ($char == $columnSeparator)) {
-                               // Debug message
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
-
                                // Add this line to the array
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
                                array_push($lineArray, $column);
 
-                               // Debug message
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - After add!', __METHOD__, __LINE__, count($lineArray)));
-
                                // Clear variable ...
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - After add!', __METHOD__, __LINE__, count($lineArray)));
                                $column = '';
 
                                // ... and skip it
                                continue;
                        } elseif ($char == chr(34)) {
-                               // Debug message
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] column=%s ...', __METHOD__, __LINE__, $column));
-
                                // $column must be empty at this point if we are at starting quote
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] column=%s ...', __METHOD__, __LINE__, $column));
                                assert(($isInQuotes === true) || (empty($column)));
 
                                // Double-quote found, so flip variable
                                $isInQuotes = (!$isInQuotes);
 
-                               // Debug message
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] isInQuotes=%d ...', __METHOD__, __LINE__, intval($isInQuotes)));
-
                                // Skip double-quote (escaping of them is not yet supported)
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] isInQuotes=%d ...', __METHOD__, __LINE__, intval($isInQuotes)));
                                continue;
                        }
 
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding char=%s ...', __METHOD__, __LINE__, $idx, $char));
-
                        // Add char to column
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding char=%s ...', __METHOD__, __LINE__, $idx, $char));
                        $column .= $char;
-               } // END - for
+               }
 
                // Is there something outstanding?
                if (!empty($column)) {
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
-
                        // Then don't forget this. :-)
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
                        array_push($lineArray, $column);
 
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - After add!', __METHOD__, __LINE__, count($lineArray)));
-               } // END - if
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
+               }
 
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
                return $lineArray;
        }
 
index 0e2c415c875f7a3bcc66fe2371268fb65f3f5cff..6f0c5a146275b35e016e4f64ce65990f0bfd2602 100644 (file)
@@ -175,7 +175,7 @@ abstract class BaseIndex extends BaseFrameworkSystem {
         */
        protected function initIndex (SplFileInfo $fileInfoInstance) {
                // Get a file i/o pointer instance for index file
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileInfoInstance=%s - CALLED!', $fileInfoInstance));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
                $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
 
                // Get iterator instance
index 952f1afbf4eca5b6b834f18eb77a7d51671abd51..1a8783e425d56d15029b0517caf437b8f469879b 100644 (file)
@@ -54,7 +54,7 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
         */
        public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
                // Get a new instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance=%s - CALLED!', $fileInfoInstance));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
                $indexInstance = new FileStackIndex();
 
                // Initialize index
index 360996c23476f309587c5573d73c1eb342663952..98aae71f26f73052519bb16dd2956abb0ab58fed 100644 (file)
@@ -163,7 +163,7 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
         */
-       public function read (int $bytes = NULL) {
+       public function read (int $bytes = 0) {
                // Call block instance
                return $this->getBlockInstance()->read($bytes);
        }
index 3debd0f0bb9ecb336f76fd88a339071b6b071e7e..9dcae9763f803a0bdc145f9f6bd8af02a543a6b4 100644 (file)
@@ -118,7 +118,7 @@ class ConsoleOutput extends BaseOutput implements OutputStreamer {
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
index eeaa83943a1dd62b9df373c7a4194ea0137e470e..7875e00127c42a51c701dfe8dba05ea36e89f6dc 100644 (file)
@@ -124,7 +124,7 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
index dea301530e67f959d5fc6252ffd120133902dc4b..cdbcf57c6d3523615d44f3aa4fa104ea7a2a0a64 100644 (file)
@@ -122,7 +122,7 @@ class DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStr
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-ERROR-LOG-OUTPUT: offset=' . $offset . ',whence=' . $whence);
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
index 6e448d7dda9f3eeec2f9a7f90f2b8bef951d73fa..2f87522c15b5abb4c1eb458a2f73396a9771fc10 100644 (file)
@@ -111,7 +111,7 @@ class DebugWebOutput extends BaseDebugOutput implements Debugger, OutputStreamer
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
index d9c8ac692dc5cecb37455fdebdb49964df51dbbe..44e24e01e69364cefa13eaa24489ff8d9ea78391 100644 (file)
@@ -104,7 +104,7 @@ class WebOutput extends BaseOutput implements OutputStreamer, Registerable {
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
index a5a2eaa69d76f30d7ff437ed9586919073a832d9..abce939f8640135fc6bcd0979aa5dc27792d5381 100644 (file)
@@ -16,6 +16,7 @@ use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SplFileInfo;
 use \UnexpectedValueException;
 
@@ -217,15 +218,22 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
         * @param       $fileInfoInstance       An instance of a SplFileInfo class
         * @param       $type           Type of this stack (e.g. url_source for URL sources)
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is invalid
         * @todo        Currently the stack file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole stack file.
         */
        protected function initFileStack (SplFileInfo $fileInfoInstance, string $type) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance[%s]=%s,type=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $type));
+               if (empty($type)) {
+                       // Invalid parameter
+                       throw new InvalidArgumentException('Parameter "type" is empty');
+               }
+
                // Get a stack file instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance=%s,type=%s - CALLED!', $fileInfoInstance, $type));
-               $fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileInfoInstance, $this));
+               $stackInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileInfoInstance, $this));
 
                // Get iterator instance
-               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance));
+               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($stackInstance));
 
                // Set iterator here
                $this->setIteratorInstance($iteratorInstance);
index 1e2de933277c313ec63b6988e26dc3d94c655f05..3fe663d31be0e154ccd3b3d7f88b82232cbd02eb 100644 (file)
@@ -42,7 +42,7 @@ interface Streamable extends FrameworkInterface {
         * @param       $whence         Added to offset (default: only use offset to seek to)
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         */
-       function seek ($offset, $whence = SEEK_SET);
+       function seek (int $offset, int $whence = SEEK_SET);
 
        /**
         * Size of file stack
index faa6415720ecaca04388cb1851062774c9b9797c..b146de2308f0c9c90dcfe491936933b525045222 100644 (file)
@@ -52,6 +52,6 @@ interface InputPointer extends StreamableInput, FilePointer {
         *                                                                      is not set by setFileObject()
         * @throws      InvalidResourceException        If there is being set
         */
-       function read (int $bytes = NULL);
+       function read (int $bytes = 0);
 
 }
index b93ace41d438e4296208860bf6491db3408863a5..4a497bf3c5efb9b768b044cbd74076d5f041a246 100644 (file)
@@ -50,7 +50,7 @@ interface SeekableWritableFileIterator extends SeekableIterator {
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
         */
-       function read (int $bytes);
+       function read (int $bytes = 0);
 
        /**
         * Analyzes entries in index file. This will count all found (and valid)
index d145b3bb72a36a3b469e9d1eaa9a3b1b1ce37a9a..d2a2a4321ae3c3e8495c5d7ed4b20a91583f1a38 100644 (file)
@@ -156,7 +156,7 @@ class FileIoHandler extends BaseMiddleware implements IoHandler {
         * @param       $whence         Added to offset (default: only use offset to seek to)
         * @return      $status         Status of file seek: 0 = success, -1 = failed
         */
-       public function seek ($offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                $this->partialStub('offset=' . $offset . ',whence=' . $whence);
        }