]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 7 Jan 2021 20:31:01 +0000 (21:31 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 7 Jan 2021 20:31:01 +0000 (21:31 +0100)
- fixed bad calls on no-longer existing iterator

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/file_directories/binary/class_BaseBinaryFile.php
framework/main/classes/index/file/stack/class_FileStackIndex.php
framework/main/classes/stacker/file/class_BaseFileStack.php

index d2adfe87c170821c0672e1dc509384295cfaf5b1..1b1594ffa16ce772f600b87c9ac1982f88d37078 100644 (file)
@@ -919,7 +919,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
 
                // Left part is the actual block, right one the back-buffer data, if found
                //* 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)));
+               //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true)));
                $this->setCurrentBlock($dataArray[0]);
 
                // Is back buffere data found?
index e74177abd78bf25a8c149aae81456d1b99f6725f..799db1cb1faf3d505632c636702cd83a80b0b213 100644 (file)
@@ -112,9 +112,9 @@ class FileStackIndex extends BaseFileIndex implements IndexableStack, Registerab
 
                // Gap position cannot be smaller or equal than header length
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,hash=%s,gapPosition=%s', $stackName, $data[StackableFile::ARRAY_NAME_HASH], $gapPosition));
-               if ($gapPosition <= ($this->getIteratorInstance()->getHeaderSize() + 1)) {
+               if ($gapPosition <= ($this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize() + 1)) {
                        // Not valid gap position returned
-                       throw new UnexpectedValueException(sprintf('gapPosition[%s]=%d is smaller or equal headerSize+1=%d', gettype($gapPosition), $gapPosition, ($this->getIteratorInstance()->getHeaderSize() + 1)));
+                       throw new UnexpectedValueException(sprintf('gapPosition[%s]=%d is smaller or equal headerSize+1=%d', gettype($gapPosition), $gapPosition, ($this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize() + 1)));
                }
 
                // Then write the data at that gap
index 3eaa1f1d6055698e5541b1f589fcf78e547323cd..c82e62c30c6f6999c75f79a328b9d51622793536 100644 (file)
@@ -76,17 +76,21 @@ abstract class BaseFileStack extends BaseStacker {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
                $this->getIteratorInstance()->rewind();
 
+               // Get header size
+               $headerSize = $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize();
+
                // 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: headerSize=%d', $headerSize));
+               $data = $this->getIteratorInstance()->getBinaryFileInstance()->read($headerSize);
 
                // 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()) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()));
+               if (strlen($data) != $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()) {
                        // Bad data length
                        throw new UnexpectedValueException(sprintf('data(%d)=%s does not match iteratorInstance->headerSize=%d',
                                strlen($data),
                                $data,
-                               $this->getIteratorInstance()->getHeaderSize()
+                               $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()
                        ));
                } elseif (empty(trim($data, chr(0)))) {
                        // Empty header, file is freshly pre-allocated
@@ -109,7 +113,7 @@ abstract class BaseFileStack extends BaseStacker {
 
                // And update seek position
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->updateSeekPosition() ...');
-               $this->getIteratorInstance()->updateSeekPosition();
+               $this->getIteratorInstance()->getBinaryFileInstance()->updateSeekPosition();
 
                /*
                 * Now split it:
@@ -155,7 +159,7 @@ abstract class BaseFileStack extends BaseStacker {
                $header[2] = hex2bin($header[2]);
 
                // Set header here
-               $this->getIteratorInstance()->setHeader($header);
+               $this->getIteratorInstance()->getBinaryFileInstance()->setHeader($header);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
@@ -177,13 +181,13 @@ abstract class BaseFileStack extends BaseStacker {
                        chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
 
                        // Padded total entries
-                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
+                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
 
                        // Separator count<->seek position
                        chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
 
                        // Padded seek position
-                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT),
+                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT),
 
                        // Separator position<->entries
                        chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
@@ -191,7 +195,7 @@ abstract class BaseFileStack extends BaseStacker {
 
                // Write it to disk (header is always at seek position 0)
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header));
-               $this->getIteratorInstance()->writeAtPosition(0, $header);
+               $this->getIteratorInstance()->getBinaryFileInstance()->writeAtPosition(0, $header);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');
@@ -235,11 +239,11 @@ abstract class BaseFileStack extends BaseStacker {
 
                // Setting it
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Setting headerSize=%d ...', $headerSize));
-               $this->getIteratorInstance()->setHeaderSize($headerSize);
+               $this->getIteratorInstance()->getBinaryFileInstance()->setHeaderSize($headerSize);
 
                // Init counters and gaps array
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->initCountersGapsArray() ...');
-               $this->getIteratorInstance()->initCountersGapsArray();
+               $this->getIteratorInstance()->getBinaryFileInstance()->initCountersGapsArray();
 
                /*
                 * Get stack index instance. This can be used for faster
@@ -253,14 +257,14 @@ abstract class BaseFileStack extends BaseStacker {
                $this->setIndexInstance($indexInstance);
 
                // Is the file's header initialized?
-               if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
+               if (!$this->getIteratorInstance()->getBinaryFileInstance()->isFileHeaderInitialized()) {
                        // 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');
+                       $this->getIteratorInstance()->getBinaryFileInstance()->preAllocateFile('file_stack');
 
                        // Then create file header
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: this->iteratorInstance->createFileHeader() ...');
-                       $this->getIteratorInstance()->createFileHeader();
+                       $this->getIteratorInstance()->getBinaryFileInstance()->createFileHeader();
                }
 
                // Load the file header
@@ -276,7 +280,7 @@ abstract class BaseFileStack extends BaseStacker {
                         * be analyzed and the index rebuild.
                         */
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->analyzeFileStructure() ...');
-                       $this->getIteratorInstance()->analyzeFileStructure();
+                       $this->getIteratorInstance()->getBinaryFileInstance()->analyzeFileStructure();
 
                        // Rebuild index from file
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Calling this->iteratorInstance->rebuildIndexFromStack(%s) ...', $this->__toString()));
@@ -316,7 +320,7 @@ abstract class BaseFileStack extends BaseStacker {
                 * Now add the value to the file stack which returns gap position, a
                 * hash and length of the raw data.
                 */
-               $data = $this->getIteratorInstance()->writeValueToFile($stackerName, $value);
+               $data = $this->getIteratorInstance()->getBinaryFileInstance()->writeValueToFile($stackerName, $value);
 
                // Add the hash and gap position to the index
                //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: data=%s', print_r($data, true));
@@ -487,7 +491,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public function isStackInitialized (string $stackerName) {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -497,7 +501,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public function isEndOfFileReached () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -509,7 +513,7 @@ abstract class BaseFileStack extends BaseStacker {
        public function getStackCount (string $stackerName) {
                // Now, simply return the found count value, this must be up-to-date then!
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackerName=%s - CALLED!', $stackerName));
-               $count = $this->getIteratorInstance()->getCounter();
+               $count = $this->getIteratorInstance()->getBinaryFileInstance()->getCounter();
 
                // Return count
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: count=%d - EXIT!', $count));
@@ -551,7 +555,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public function initCountersGapsArray () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -561,7 +565,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public final function getHeaderSize () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -572,7 +576,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public final function setHeaderSize (int $headerSize) {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -582,7 +586,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public final function getHeader () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -593,7 +597,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public final function setHeader (array $header) {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -603,7 +607,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public function updateSeekPosition () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -613,7 +617,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public final function getCounter () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -627,8 +631,7 @@ abstract class BaseFileStack extends BaseStacker {
         */
        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);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -641,8 +644,7 @@ abstract class BaseFileStack extends BaseStacker {
         */
        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);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -654,8 +656,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public function writeValueToFile (string $stackName, $value) {
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,value[%s]=%s', $stackName, gettype($value), print_r($value, true)));
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -668,8 +669,7 @@ abstract class BaseFileStack extends BaseStacker {
         */
        public function searchNextGap (int $length) {
                // Not supported here
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: length=%d - CALLED!', $length));
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -680,7 +680,7 @@ abstract class BaseFileStack extends BaseStacker {
        public function getFileSize () {
                // Call iterator's method
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
-               $size = $this->getIteratorInstance()->getFileSize();
+               $size = $this->getIteratorInstance()->getBinaryFileInstance()->getFileSize();
 
                // Return size
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: size=%d - EXIT!', $size));
@@ -708,22 +708,22 @@ abstract class BaseFileStack extends BaseStacker {
 
                // Search for next free gap
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,rawData()=%d', $stackName, $hash, strlen($rawData)));
-               $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
+               $gapPosition = $this->getIteratorInstance()->getBinaryFileInstance()->searchNextGap(strlen($rawData));
 
                // Gap position cannot be smaller than header length + 1
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: gapPosition=%d', $gapPosition));
-               if ($gapPosition <= $this->getIteratorInstance()->getHeaderSize()) {
+               if ($gapPosition <= $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()) {
                        // Improper gap position
                        throw new UnexpectedValueException(sprintf('gapPosition[%s]=%d is not larger than headerSize=%d',
                                gettype($gapPosition),
                                $gapPosition,
-                               $this->getIteratorInstance()->getHeaderSize()
+                               $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()
                        ));
                }
 
                // Then write the data at that gap
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,gapPosition=%s', $stackName, $hash, $gapPosition));
-               $this->getIteratorInstance()->writeData($gapPosition, $rawData);
+               $this->getIteratorInstance()->getBinaryFileInstance()->writeData($gapPosition, $rawData);
 
                // Return gap position, hash and length of raw data
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,rawData()=%d - EXIT!', $stackName, $hash, strlen($rawData)));