Rewrites:
authorRoland Häder <roland@mxchange.org>
Mon, 7 Dec 2020 14:16:48 +0000 (15:16 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 7 Dec 2020 14:16:48 +0000 (15:16 +0100)
- more thrown exceptions
- more debug logging (currently messing up phpunit output)
- more type-hints for primitive variables added
- writeAtPosition() must be used instead of writeData() as the later one
  increments the counter
- debug log files could contain non-text data, so let's treat them as as text
  anyway ...

Signed-off-by: Roland Häder <roland@mxchange.org>
20 files changed:
contrib/missing-methods.sh
framework/main/classes/database/result/class_CachedDatabaseResult.php
framework/main/classes/file_directories/binary/class_BaseBinaryFile.php
framework/main/classes/file_directories/class_BaseAbstractFile.php
framework/main/classes/file_directories/class_BaseFileIo.php
framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.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/classes/stacker/file/fifo/class_FiFoFileStack.php
framework/main/interfaces/block/class_Block.php
framework/main/interfaces/debug/class_Debugger.php
framework/main/interfaces/io/output/class_OutputStreamer.php
framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php

index 6c7ac041a730de5ddd57a0fb5d8649e103ba78f5..91dc124127826829f1701070c75d1c2b6681a9de 100755 (executable)
@@ -13,4 +13,4 @@ then
        exit 255
 fi
 
-grep __call "${DEBUG_FILE}" | cut -d "[" -f 4 | cut -d "]" -f 1
+grep -a __call "${DEBUG_FILE}" | cut -d "[" -f 4 | cut -d "]" -f 1
index 664270e653d7821513f33c1da6ea04e8e1a40cd9..747660386c1e29384599f21e9ca3e84102d43e16 100644 (file)
@@ -174,7 +174,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         * @param       $index  Index to seek for
         * @return      void
         */
-       public function seek ($index) {
+       public function seek (int $index) {
                // Rewind to beginning
                $this->rewind();
 
index 04e6da4eef30c6fd093025026cebfce592b9ac75..187ac493e0e64213d735ec799dab392f508b6deb 100644 (file)
@@ -13,6 +13,7 @@ use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
 use \BadMethodCallException;
 use \InvalidArgumentException;
 use \SplFileInfo;
+use \UnexpectedValueException;
 
 /**
  * A general binary file class
@@ -179,28 +180,20 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      $isGapsOnly             Whether the abstracted file only contains gaps
         */
        private function isFileOnlyGaps () {
-               // First/last gap found?
-               /* Only for debugging
-               if (isset($this->gaps[0])) {
-                       // Output first and last gap
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] this->gaps[0]=%s,this->gaps[%s]=%s', print_r($this->gaps[0], true), (count($this->gaps) - 1), print_r($this->gaps[count($this->gaps) - 1], true)));
-               }
-               */
-
-               // Now count every gap
+               // Count every gap
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $gapsSize = 0;
                foreach ($this->gaps as $gap) {
                        // Calculate size of found gap: end-start including both
                        $gapsSize += ($gap[self::GAPS_INDEX_END] - $gap[self::GAPS_INDEX_START]);
                }
 
-               // Debug output
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] gapsSize=%s,this->headerSize=%s', $gapsSize, $this->getHeaderSize()));
-
                // Total gap size + header size must be same as file size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gapsSize=%s,this->headerSize=%s', $gapsSize, $this->getHeaderSize()));
                $isGapsOnly = (($this->getHeaderSize() + $gapsSize) == $this->getFileSize());
 
                // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isGapsOnly=%d - EXIT!', intval($isGapsOnly)));
                return $isGapsOnly;
        }
 
@@ -213,13 +206,17 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      void
         */
        public function initCountersGapsArray () {
-               // Init counter and seek position
+               // Init counter and seek position to header size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $this->setCounter(0);
-               $this->setSeekPosition(0);
+               $this->setSeekPosition($this->getHeaderSize());
 
                // Init arrays
                $this->gaps = [];
                $this->damagedEntries = [];
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
        }
 
        /**
@@ -270,7 +267,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      $seekPosition   Current seek position (stored here in object)
         */
        public final function getSeekPosition () {
-               // Get it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Getting this->seekPosition=%d - CALLED!', $this->seekPosition));
                return $this->seekPosition;
        }
 
@@ -281,7 +278,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      void
         */
        protected final function setSeekPosition (int $seekPosition) {
-               // And set it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting seekPosition=%d - CALLED!', $seekPosition));
                $this->seekPosition = $seekPosition;
        }
 
@@ -291,40 +288,43 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      void
         */
        public function updateSeekPosition () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!'));
-
                // Get key (= seek position)
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $seekPosition = $this->key();
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Setting seekPosition=%s', $seekPosition));
 
                // And set it here
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
                $this->setSeekPosition($seekPosition);
 
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!'));
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
         * Seeks to beginning of file, updates seek position in this object and
         * flushes the header.
         *
+        * @param       $flushHeader    Wether the file's header should be flushed (default: false)
         * @return      void
         */
-       protected function rewindUpdateSeekPosition () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!'));
-
-               // flushFileHeader must be callable
-               assert(is_callable(array($this, 'flushFileHeader')));
-
+       protected function rewindUpdateSeekPosition (bool $flushHeader = false) {
                // Seek to beginning of file
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: flushHeader=%d - CALLED!', intval($flushHeader)));
                $this->rewind();
 
                // And update seek position ...
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...');
                $this->updateSeekPosition();
 
-               // ... to write it back into the file
-               $this->flushFileHeader();
+               // Flush headers?
+               if ($flushHeader) {
+                       // ... to write it back into the file
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...');
+                       $this->flushFileHeader();
+               }
 
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!'));
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -333,12 +333,12 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * @return      void
         */
        protected function seekToOldPosition () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!'));
-
                // Seek to currently ("old") saved position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $this->seek($this->getSeekPosition());
 
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!'));
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -346,12 +346,21 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         *
         * @param       $str            String to look in
         * @return      $isFound        Whether the block separator has been found
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public static function isBlockSeparatorFound ($str) {
+       public static function isBlockSeparatorFound (string $str) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: str=%s - CALLED!', $str));
+               if (empty($str)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "str" is empty');
+               }
+
                // Determine it
                $isFound = (strpos($str, chr(self::SEPARATOR_ENTRIES)) !== false);
 
                // Return result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isFound=%d - EXIT!', intval($isFound)));
                return $isFound;
        }
 
@@ -362,7 +371,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        private function initBackBuffer () {
                // Simply call the setter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $this->setBackBuffer('');
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -388,7 +401,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
        /**
         * Setter for currentBlock field
         *
-        * @param       $currentBlock           Characters to set a currently loaded block
+        * @param       $currentBlock   Characters to set a currently loaded block
         * @return      void
         */
        private function setCurrentBlock (string $currentBlock) {
@@ -446,20 +459,26 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                }
 
                // Write data at given position
-               $this->getPointerInstance()->writeAtPosition($seekPosition, $data);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,%s) ...', $seekPosition, $data));
+               $this->writeAtPosition($seekPosition, $data);
 
                // Increment counter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->incrementCounter() ...');
                $this->incrementCounter();
 
                // Update seek position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...');
                $this->updateSeekPosition();
 
                // Flush the header?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: flushHeader=%d', intval($flushHeader)));
                if ($flushHeader === true) {
                        // Flush header
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...');
                        $this->flushFileHeader();
 
                        // Seek to old position
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->seekToOldPosition() ...');
                        $this->seekToOldPosition();
                }
 
@@ -467,6 +486,34 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
+       /**
+        * Writes at given position by seeking to it.
+        *
+        * @param       $seekPosition   Seek position in file
+        * @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 $dataStream) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d,dataStream(%d)=%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');
+               }
+
+               // Call pointer's method
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->pointerInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
+               $status = $this->getPointerInstance()->writeAtPosition($seekPosition, $dataStream);
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: status[%s]=%d - EXIT!', gettype($status), $status));
+               return $status;
+       }
+
        /**
         * Marks the currently loaded block as empty (with length of the block)
         *
@@ -476,7 +523,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        protected function markCurrentBlockAsEmpty (int $length) {
                // Validate parameter
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length));
+               /* 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));
@@ -492,7 +539,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                ));
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -508,20 +555,18 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                // Is the file initialized?
                if ($this->isFileInitialized()) {
                        // Some bytes has been written, so rewind to start of it.
-                       $rewindStatus = $this->rewind();
-
-                       // 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('BASE-BINARY-FILE: Could not rewind().');
-                       }
+                       $this->rewind();
 
                        // Read file header
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->readFileHeader() ...');
                        $this->readFileHeader();
 
+                       // Get header count
+                       $headerCount = count($this->getHeader());
+
                        // The above method does already check the header
-                       $isInitialized = true;
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: headerCount=%d', $headerCount));
+                       $isInitialized = ($headerCount > 0);
                }
 
                // Return result
@@ -536,21 +581,21 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        public function isFileInitialized () {
                // Get it from iterator which holds the pointer instance. If false is returned
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $fileSize = $this->size();
-               //* 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
                 * that the pointer class does not work correctly.
                 */
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize[%s]=%d', gettype($fileSize), $fileSize));
                assert(is_int($fileSize));
 
                // Is more than 0 returned?
                $isInitialized = ($fileSize > 0);
 
                // Return result
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized)));
                return $isInitialized;
        }
 
@@ -558,20 +603,27 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * Creates the assigned file
         *
         * @return      void
+        * @throws      BadMethodCallException  If this file's header is already initialized
         */
        public function createFileHeader () {
                // The file's header should not be initialized here
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               assert(!$this->isFileHeaderInitialized());
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               if ($this->isFileHeaderInitialized()) {
+                       // Bad method call
+                       //* DEBUG-DIE: */ die(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, TRUE)));
+                       throw new BadMethodCallException('File header is already initialized but method called');
+               }
 
                // Simple flush file header which will create it.
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...');
                $this->flushFileHeader();
 
                // Rewind seek position (to beginning of file) and update/flush file header
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewindUpdateSeekPosition() ...');
                $this->rewindUpdateSeekPosition();
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -597,18 +649,18 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
 
                // Calculate minimum length for one entry
-               $minLengthEntry = $this->getBlockInstance()->calculateMinimumBlockLength();
+               $minimumBlockLength = $this->getBlockInstance()->calculateMinimumBlockLength();
 
                // Calulcate seek position
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minLengthEntry=%s', $minLengthEntry));
-               $seekPosition = $minLengthEntry * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minimumBlockLength=%s', $minimumBlockLength));
+               $seekPosition = $minimumBlockLength * 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('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
-               $this->writeData($seekPosition, chr(0));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,NUL) ...', $seekPosition));
+               $this->writeAtPosition($seekPosition, chr(0));
 
-               // Rewind seek position (to beginning of file) and update/flush file header
-               $this->rewindUpdateSeekPosition();
+               // Rewind seek position
+               $this->rewind();
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
@@ -631,7 +683,7 @@ abstract class BaseBinaryFile 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 (int $offset, $whence = SEEK_SET) {
+       public function seek (int $offset, int $whence = SEEK_SET) {
                // Call pointer instance
                return $this->getPointerInstance()->seek($offset, $whence);
        }
@@ -667,7 +719,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        public function analyzeFile () {
                // Make sure the file is initialized
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                if (!$this->isFileInitialized()) {
                        // Bad method call
                        throw new BadMethodCallException('Method called but file is not initialized.');
@@ -725,7 +777,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                                $this->doRunDefragmentation();
                        }
                }
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -736,16 +788,16 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        public function next () {
                // Is there nothing to read?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                if (!$this->valid()) {
                        // Nothing to read
                        return;
                }
 
                // First calculate minimum block length
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: key()=%d', $this->key()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: key()=%d', $this->key()));
                $length = $this->getBlockInstance()->calculateMinimumBlockLength();
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%s', $length));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
 
                // Read possibly back-buffered bytes from previous call of next().
                $data = $this->getBackBuffer();
@@ -755,20 +807,21 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                 * "block" may not fit, so this loop will continue until the EOB or EOF
                 * has been reached whatever comes first.
                 */
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data()=%d', strlen($data)));
-               while ((!$this->isEndOfFileReached()) && (!self::isBlockSeparatorFound($data))) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data()=%d', strlen($data)));
+               while ((!$this->isEndOfFileReached()) && (empty($data) || !self::isBlockSeparatorFound($data))) {
                        // Then read the next possible block
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->read(%d) ...', $length));
                        $block = $this->read($length);
 
                        // Is it all empty?
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: block()=%d,length=%s', strlen($block), $length));
-                       if (strlen(trim($block)) == 0) {
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: block()=%d,length=%s', strlen($block), $length));
+                       if (strlen(trim($block, chr(0))) == 0) {
                                // Mark this block as empty
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling markCurrentBlockAsEmpty(%d) ...', strlen($block)));
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling markCurrentBlockAsEmpty(%d) ...', strlen($block)));
                                $this->markCurrentBlockAsEmpty(strlen($block));
 
                                // Skip to next block
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CONTINUE!');
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CONTINUE!');
                                continue;
                        }
 
@@ -776,17 +829,17 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                        $data .= $block;
 
                        // A debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data()=%d', strlen($data)));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data()=%d', strlen($data)));
                }
 
                // EOF reached?
                if ($this->isEndOfFileReached()) {
                        // Set whole data as current read block
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling setCurrentBlock(%d) ...', strlen($data)));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling setCurrentBlock(%d) ...', strlen($data)));
                        $this->setCurrentBlock($data);
 
                        // Then abort here silently
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EOF reached - EXIT!');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EOF reached - EXIT!');
                        return;
                }
 
@@ -800,7 +853,8 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                $dataArray = explode(chr(self::SEPARATOR_ENTRIES), $data);
 
                // This array must contain two elements
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: dataArray=' . print_r($dataArray, true));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray()=%d', count($dataArray)));
+               //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true)));
                if (count($dataArray) != 2) {
                        // Bad count
                        throw new UnexpectedValueException(sprintf('dataArray()=%d is not expected, want 2', count($dataArray)));
@@ -811,7 +865,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                $this->setBackBuffer($dataArray[1]);
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -819,6 +873,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         * This method will return true if an emptied (nulled) entry has been found.
         *
         * @return      $isValid        Whether the next entry is valid
+        * @throws      UnexpectedValueException        If some value is not expected
         */
        public function valid () {
                // First calculate minimum block length
@@ -826,30 +881,38 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
                $length = $this->getBlockInstance()->calculateMinimumBlockLength();
 
                // Short be more than zero!
-               assert($length > 0);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
+               if ($length < 1) {
+                       // Throw UVE
+                       throw new UnexpectedValueException(sprintf('length=%d is not expected', $length));
+               }
 
                // Get current seek position
                $seekPosition = $this->key();
 
                // Then try to read it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
                $data = $this->read($length);
 
                // If some bytes could be read, all is fine
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data[%s]()=%d', gettype($data), strlen($data)));
                $isValid = ((is_string($data)) && (strlen($data) > 0));
 
                // Get header size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d', intval($isValid)));
                $headerSize = $this->getHeaderSize();
 
                // Is the seek position at or beyond the header?
                if ($seekPosition >= $headerSize) {
                        // Seek back to old position
-                       $this->seek($seekPosition);
+                       $isValid = ($isValid && $this->seek($seekPosition) === 0);
                } else {
                        // Seek directly behind the header
-                       $this->seek($headerSize);
+                       $isValid = ($isValid && $this->seek($headerSize) === 0);
                }
 
                // Return result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d - EXIT!', intval($isValid)));
                return $isValid;
        }
 
@@ -860,7 +923,12 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        public function key () {
                // Call pointer instance
-               return $this->getPointerInstance()->determineSeekPosition();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               $key = $this->getPointerInstance()->determineSeekPosition();
+
+               // Return key
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: key[%s]=%d - EXIT!', gettype($key), $key));
+               return $key;
        }
 
        /**
@@ -870,7 +938,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        public function readFileHeader () {
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $this->getBlockInstance()->readFileHeader();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -880,7 +952,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile {
         */
        public function flushFileHeader () {
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $this->getBlockInstance()->flushFileHeader();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
index f72d77534ef29c4fcea109b8c3b4548488dd54de..07524bcabcd83ca3abcfc1b954c368601aa225aa 100644 (file)
@@ -117,6 +117,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         */
        public final function getCounter () {
                // Get it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-ABSTRACT-FILE: Getting this->totalEntries=%d ... - CALLED!', $this->totalEntries));
                return $this->totalEntries;
        }
 
@@ -128,6 +129,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         */
        protected final function setCounter (int $counter) {
                // Set it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-ABSTRACT-FILE: Setting this->totalEntries=%d ... - CALLED!', $counter));
                $this->totalEntries = $counter;
        }
 
@@ -138,7 +140,11 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         */
        protected final function incrementCounter () {
                // Get it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: CALLED!');
                $this->totalEntries++;
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: EXIT!');
        }
 
        /**
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;
        }
 
index 4e79954fad93332afea415cd7348f92db2a45bfa..2805546ff35208997b53fef82e19eeab0b482ff7 100644 (file)
@@ -149,7 +149,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                }
 
                // First seek to it, if file size is larger than zero
-               if ($this->getFileSize() > 0 && !$this->seek($seekPosition)) {
+               if (($this->getFileSize() > 0 || $seekPosition > 0) && $this->seek($seekPosition) === -1) {
                        // Could not seek
                        throw new InvalidArgumentException(sprintf('Could not seek to seekPosition=%d', $seekPosition));
                }
@@ -165,12 +165,15 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
        /**
         * Rewinds to the beginning of the file
         *
-        * @return      $status         Status of this operation
+        * @return      void
         */
        public function rewind () {
                // Rewind the pointer
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
-               return $this->getFileObject()->rewind();
+               $this->getFileObject()->rewind();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: EXIT!');
        }
 
        /**
@@ -217,7 +220,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         */
        public function read (int $bytes = 0) {
                // Validatre parameter
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: bytes=%d - CALLED!', $bytes));
+               /* 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));
@@ -233,7 +236,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));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%s - EXIT!', gettype($data), $data));
                return $data;
        }
 
index 21a79b7de90db59812b24766444abdef30b7cd63..cd9648b96086ded25ef0cb882c95f200be2c9e77 100644 (file)
@@ -80,6 +80,10 @@ abstract class BaseIndex extends BaseFrameworkSystem {
                                $data,
                                $this->getIteratorInstance()->getHeaderSize()
                        ));
+               } elseif (empty(trim($data, chr(0)))) {
+                       // Empty file header
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: File header is empty - EXIT!');
+                       return;
                } elseif (substr($data, -1, 1) != chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) {
                        // Bad last character
                        throw new UnexpectedValueException(sprintf('data=%s does not end with "%s"',
@@ -92,6 +96,7 @@ abstract class BaseIndex extends BaseFrameworkSystem {
                $data = substr($data, 0, -1);
 
                // And update seek position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->updateSeekPosition() ...');
                $this->getIteratorInstance()->updateSeekPosition();
 
                /*
@@ -149,7 +154,8 @@ abstract class BaseIndex extends BaseFrameworkSystem {
                );
 
                // Write it to disk (header is always at seek position 0)
-               $this->getIteratorInstance()->writeData(0, $header, false);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header));
+               $this->getIteratorInstance()->writeAtPosition(0, $header);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
@@ -174,30 +180,49 @@ abstract class BaseIndex extends BaseFrameworkSystem {
                $this->setIteratorInstance($iteratorInstance);
 
                // Calculate header size
-               $this->getIteratorInstance()->setHeaderSize(
+               $headerSize = (
                        strlen(Indexable::INDEX_MAGIC) +
                        strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
                        BaseBinaryFile::LENGTH_COUNT +
                        strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES))
                );
 
+               // Set it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: Setting headerSize=%d ...', $headerSize));
+               $this->getIteratorInstance()->setHeaderSize($headerSize);
+
                // Init counters and gaps array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->initCountersGapsArray() ...');
                $this->getIteratorInstance()->initCountersGapsArray();
 
+               // Default is not created
+               $created = false;
+
                // Is the file's header initialized?
                if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
-                       // No, then create it (which may pre-allocate the index)
+                       // First pre-allocate a bit
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->preAllocateFile(index) ...');
+                       $this->getIteratorInstance()->preAllocateFile('index');
+
+                       // Then write file header
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->createFileHeader() ...');
                        $this->getIteratorInstance()->createFileHeader();
 
-                       // And pre-allocate a bit
-                       $this->getIteratorInstance()->preAllocateFile('index');
+                       // Mark as freshly created
+                       $created = true;
                }
 
                // Load the file header
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->readFileHeader() ...');
                $this->readFileHeader();
 
-               // Count all entries in file
-               $this->getIteratorInstance()->analyzeFile();
+               // Freshly created?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: created=%d', intval($created)));
+               if (!$created) {
+                       // Count all entries in file
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->analyzeFile() ...');
+                       $this->getIteratorInstance()->analyzeFile();
+               }
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
index efb563cc2da5cfe9032ec99f1496c91ce24a989a..0d1692463daa09ecf6b4abd484c82db45f389ea8 100644 (file)
@@ -124,4 +124,32 @@ class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
                }
        }
 
+       /**
+        * Writes at given position by seeking to it.
+        *
+        * @param       $seekPosition   Seek position in file
+        * @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 $dataStream) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: seekPosition=%d,dataStream(%d)=%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');
+               }
+
+               // Call iterated object's method
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: Calling this->iteratorInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
+               $status = $this->getIteratorInstance()->writeAtPosition($seekPosition, $dataStream);
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: status[%s]=%d - EXIT!', gettype($status), $status));
+               return $status;
+       }
+
 }
index a246927c02e4585c810e0af7eb4d7743d8f12c6f..24fb278033b8a1b2cfa0dbfbda16119ed5cd4317 100644 (file)
@@ -153,11 +153,10 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
        public function rewind () {
                // Call block instance
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
-               $status = $this->getBlockInstance()->rewind();
+               $this->getBlockInstance()->rewind();
 
-               // Return status
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status=%d - EXIT!', intval($status)));
-               return $status;
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -180,19 +179,20 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * Seeks to given position
         *
         * @param       $seekPosition   Seek position in file
+        * @param       $whence                 Added to offset (default: only use offset to seek to)
         * @return      $status                 Status of this operation
         * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function seek (int $seekPosition) {
+       public function seek (int $seekPosition, int $whence = SEEK_SET) {
                // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d - CALLED!', $seekPosition));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
                if ($seekPosition < 0) {
                        // Throw IAE
                        throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
                }
 
                // Call block instance
-               $status = $this->getBlockInstance()->seek($seekPosition);
+               $status = $this->getBlockInstance()->seek($seekPosition, $whence);
 
                // Return status
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status=%d - EXIT!', intval($status)));
@@ -445,12 +445,41 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
                }
 
                // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->blockInstance->writeData(%d,data()=%d,%d) ...', $seekPosition, strlen($data), intval($flushHeader)));
                $this->getBlockInstance()->writeData($seekPosition, $data, $flushHeader);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
+       /**
+        * Writes at given position by seeking to it.
+        *
+        * @param       $seekPosition   Seek position in file
+        * @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 $dataStream) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,dataStream(%d)=%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');
+               }
+
+               // Call iterated object's method
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->blockInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
+               $status = $this->getBlockInstance()->writeAtPosition($seekPosition, $dataStream);
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status[%s]=%d - EXIT!', gettype($status), $status));
+               return $status;
+       }
+
        /**
         * Getter for seek position
         *
@@ -462,7 +491,7 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
                $seekPosition = $this->getBlockInstance()->getSeekPosition();
 
                // Return position
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d - EXIT!', $seekPosition));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition));
                return $seekPosition;
        }
 
@@ -533,7 +562,7 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
                $seekPosition = $this->getBlockInstance()->searchNextGap($length);
 
                // Return position
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d - EXIT!', $seekPosition));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition));
                return $seekPosition;
        }
 
index 3ffff09fcfb9adfcfee9035b8a38af11e25494bb..1b11c51adf1481352900ea1031cace08601c5bbf 100644 (file)
@@ -95,7 +95,7 @@ class ConsoleOutput extends BaseOutput implements OutputStreamer {
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function output ($outStream = false, $stripTags = false) {
+       public final function output (string $outStream = '', bool $stripTags = false) {
                print trim($outStream) . PHP_EOL;
        }
 
index 7875e00127c42a51c701dfe8dba05ea36e89f6dc..8f7d19f6641b007d10752717bd6cf1b5f4f26ad1 100644 (file)
@@ -63,18 +63,18 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function outputStream ($output, $stripTags = false) {
+       public final function outputStream (string $output, bool $stripTags = false) {
                // Strip HTML tags out?
                if ($stripTags === true) {
                        // Prepare the output without HTML tags
                        $output = trim(html_entity_decode(strip_tags(stripslashes($output))));
-               } // END - if
+               }
 
                // Are debug times enabled?
                if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') {
                        // Output it first
                        $output = $this->getPrintableExecutionTime() . $output;
-               } // END - if
+               }
 
                // And print it out...
                printf('%s%s', str_replace('-&gt;', '->', $output), PHP_EOL);
@@ -87,11 +87,11 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function output ($outStream = false, $stripTags = false) {
+       public final function output (string $outStream = '', bool $stripTags = false) {
                // Empty output will be silently ignored
-               if ($outStream !== false) {
+               if (!empty($outStream)) {
                        $this->outputStream($outStream, $stripTags);
-               } // END - if
+               }
        }
 
        /**
index cdbcf57c6d3523615d44f3aa4fa104ea7a2a0a64..7903b910acbe96cda921f9c4ce1bf97bd39c6540 100644 (file)
@@ -61,7 +61,7 @@ class DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStr
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function outputStream ($output, $stripTags = false) {
+       public final function outputStream (string $output, bool $stripTags = false) {
                // Split multiple lines into and array to put them out line-by-line
                $errorLines = explode(chr(10), $output);
 
@@ -85,11 +85,11 @@ class DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStr
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function output ($outStream = false, $stripTags = false) {
+       public final function output (string $outStream = '', bool $stripTags = false) {
                // Empty output will be silently ignored
-               if ($outStream !== false) {
+               if (!empty($outStream)) {
                        $this->outputStream($outStream);
-               } // END - if
+               }
        }
 
        /**
index 2f87522c15b5abb4c1eb458a2f73396a9771fc10..e2656b1da4b3d1a3cc763ed74b3b90a6f94ef04d 100644 (file)
@@ -61,7 +61,7 @@ class DebugWebOutput extends BaseDebugOutput implements Debugger, OutputStreamer
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function outputStream ($output, $stripTags = false) {
+       public final function outputStream (string $output, bool $stripTags = false) {
                // Strip out any <br />
                $output = str_replace('<br />', '', $output);
                printf('<!-- %s -->' . PHP_EOL, stripslashes($output));
@@ -74,11 +74,11 @@ class DebugWebOutput extends BaseDebugOutput implements Debugger, OutputStreamer
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function output ($outStream = false, $stripTags = false) {
+       public final function output (string $outStream = '', bool $stripTags = false) {
                // Empty output will be silently ignored
-               if ($outStream !== false) {
+               if (!empty($outStream)) {
                        $this->outputStream($outStream, $stripTags);
-               } // END - if
+               }
        }
 
        /**
index 44e24e01e69364cefa13eaa24489ff8d9ea78391..6abfc10fc1068765637473678c300da81ae5eb5f 100644 (file)
@@ -82,7 +82,7 @@ class WebOutput extends BaseOutput implements OutputStreamer, Registerable {
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       public final function output ($outStream = false, $stripTags = false) {
+       public final function output (string $outStream = '', bool $stripTags = false) {
                print(stripslashes($outStream));
        }
 
index 5420523056216d65d865035bbdf9a621e9f595c6..859eebd885f5d7476a1eda9cbc33a839b9c29dbf 100644 (file)
@@ -81,9 +81,9 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
 
                // Then read it (see constructor for calculation)
                $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
 
                // Have all requested bytes been read?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
                if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
                        // Bad data length
                        throw new UnexpectedValueException(sprintf('data(%d)=%s does not match iteratorInstance->headerSize=%d',
@@ -91,6 +91,10 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                                $data,
                                $this->getIteratorInstance()->getHeaderSize()
                        ));
+               } elseif (empty(trim($data, chr(0)))) {
+                       // Empty header, file is freshly pre-allocated
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Empty file header detected - EXIT!');
+                       return;
                }
 
                // Last character must be the separator
@@ -107,6 +111,7 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                $data = substr($data, 0, -1);
 
                // And update seek position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->updateSeekPosition() ...');
                $this->getIteratorInstance()->updateSeekPosition();
 
                /*
@@ -156,7 +161,7 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                $this->getIteratorInstance()->setHeader($header);
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: EXIT!', __METHOD__, __LINE__));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
        }
 
        /**
@@ -174,13 +179,13 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                        // Separator magic<->count
                        chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
 
-                       // Total entries (will be zero) and pad it to 20 chars
+                       // Padded total entries
                        str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
 
                        // Separator count<->seek position
                        chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
 
-                       // Position (will be zero)
+                       // Padded seek position
                        str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT),
 
                        // Separator position<->entries
@@ -188,7 +193,8 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                );
 
                // Write it to disk (header is always at seek position 0)
-               $this->getIteratorInstance()->writeData(0, $header, false);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header));
+               $this->getIteratorInstance()->writeAtPosition(0, $header);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
@@ -221,7 +227,7 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                $this->setIteratorInstance($iteratorInstance);
 
                // Calculate header size
-               $this->getIteratorInstance()->setHeaderSize(
+               $headerSize = (
                        strlen(StackableFile::STACK_MAGIC) +
                        strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
                        BaseBinaryFile::LENGTH_COUNT +
@@ -230,28 +236,48 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                        strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES))
                );
 
+               // Setting it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Setting headerSize=%d ...', $headerSize));
+               $this->getIteratorInstance()->setHeaderSize($headerSize);
+
                // Init counters and gaps array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->initCountersGapsArray() ...');
                $this->getIteratorInstance()->initCountersGapsArray();
 
+               // Default is not created/already exists
+               $created = false;
+
                // Is the file's header initialized?
                if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
-                       // No, then create it (which may pre-allocate the stack)
+                       // First pre-allocate a bit
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->preAllocateFile(file_stack) ...');
+                       $this->getIteratorInstance()->preAllocateFile('file_stack');
+
+                       // Then create file header
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: this->iteratorInstance->createFileHeader() ...');
                        $this->getIteratorInstance()->createFileHeader();
 
-                       // And pre-allocate a bit
-                       $this->getIteratorInstance()->preAllocateFile('file_stack');
+                       // Set flag
+                       $created = true;
                }
 
                // Load the file header
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->readFileHeader() ...');
                $this->readFileHeader();
 
-               // Count all entries in file
-               $this->getIteratorInstance()->analyzeFile();
+               // Not created/already exists?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: created=%d', intval($created)));
+               if (!$created) {
+                       // Count all entries in file
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->analyzeFile() ...');
+                       $this->getIteratorInstance()->analyzeFile();
+               }
 
                /*
                 * Get stack index instance. This can be used for faster
                 * "defragmentation" and startup.
                 */
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance[%s]=%s,type=%s', get_class($fileInfoInstance), $fileInfoInstance, $type));
                $indexInstance = FileStackIndexFactory::createFileStackIndexInstance($fileInfoInstance, $type);
 
                // And set it here
@@ -618,10 +644,25 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
+               // Not supported
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: seekPosition=%s,data[]=%s,flushHeader=%d', $seekPosition, gettype($data), intval($flushHeader)));
                throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
+       /**
+        * Writes at given position by seeking to it.
+        *
+        * @param       $seekPosition   Seek position in file
+        * @param       $dataStream             Data to be written
+        * @return      mixed                   Number of writes bytes or false on error
+        * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
+        */
+       public function writeAtPosition (int $seekPosition, string $dataStream) {
+               // Not supported
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+       }
+
        /**
         * Writes given value to the file and returns a hash and gap position for it
         *
index f2fce745e502b828fc5ec4b02003a8b2079a6391..42eab523b6cab53796820dad5f15eb6a0ffcba60 100644 (file)
@@ -160,12 +160,13 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         * Seeks to given position
         *
         * @param       $seekPosition   Seek position in file
+        * @param       $whence                 Added to offset (default: only use offset to seek to)
         * @return      $status                 Status of this operation
         * @throws      InvalidArgumentException        If a parameter is invalid
         */
-       public function seek (int $seekPosition) {
+       public function seek (int $seekPosition, int $whence = SEEK_SET) {
                // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: seekPosition=%d - CALLED!', $seekPosition));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
                if ($seekPosition < 0) {
                        // Invalid seek position
                        throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
index 9f593ecc7a23e872944eec16496d7725f35f4ffa..5c25324b09d69e2900a2341f4f58a93f8714c7a1 100644 (file)
@@ -139,6 +139,16 @@ interface Block extends FrameworkInterface {
         */
        function writeData (int $seekPosition, string $data, bool $flushHeader = true);
 
+       /**
+        * Writes at given position by seeking to it.
+        *
+        * @param       $seekPosition   Seek position in file
+        * @param       $dataStream             Data to be written
+        * @return      mixed                   Number of writes bytes or false on error
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        */
+       function writeAtPosition (int $seekPosition, string $dataStream);
+
        /**
         * Searches for next suitable gap the given length of data can fit in
         * including padding bytes.
index 437a462c412da0baad52ddf301e62a4e1d189903..7f2ac43f12b39a83ef493167be65b2a323a479d3 100644 (file)
@@ -35,6 +35,6 @@ interface Debugger extends FrameworkInterface {
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       function outputStream ($output, $stripTags = false);
+       function outputStream (string $output, bool $stripTags = false);
 
 }
index b7b7ae72f078284f97580ff015671de97e95aae6..1448c698b0ea48e03ea27e8da163b29ab9ddcc4b 100644 (file)
@@ -35,6 +35,6 @@ interface OutputStreamer extends StreamableOutput {
         * @param       $stripTags      Whether HTML tags shall be stripped out
         * @return      void
         */
-       function output ($outStream = false, $stripTags = false);
+       function output (string $outStream = '', bool $stripTags = false);
 
 }
index 4a497bf3c5efb9b768b044cbd74076d5f041a246..728a3457266998c2ea1b348482fb82e0e9ff629a 100644 (file)
@@ -154,6 +154,15 @@ interface SeekableWritableFileIterator extends SeekableIterator {
         */
        function writeData (int $seekPosition, string $data, bool $flushHeader = true);
 
+       /**
+        * Writes at given position by seeking to it.
+        *
+        * @param       $seekPosition   Seek position in file
+        * @param       $data                   Data to be written
+        * @return      mixed                   Number of writes bytes or false on error
+        */
+       function writeAtPosition (int $seedPosition, string $data);
+
        /**
         * Getter for seek position
         *