]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/stacker/file/class_BaseFileStack.php
Continued:
[core.git] / framework / main / classes / stacker / file / class_BaseFileStack.php
index 4eb594316daa753a95cb3421e1657c90873620ee..303caca77c7666d0f91e05b18640b50d3c199cc7 100644 (file)
@@ -9,6 +9,7 @@ use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
 use Org\Mxchange\CoreFramework\Filesystem\File\BinaryFile;
 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
+use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
 use Org\Mxchange\CoreFramework\Stack\BaseStacker;
 use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
 use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
@@ -25,7 +26,7 @@ use \UnexpectedValueException;
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -94,7 +95,7 @@ abstract class BaseFileStack extends BaseStacker {
                                strlen($data),
                                $data,
                                $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()
-                       ));
+                       ), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
                } 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!');
@@ -108,7 +109,7 @@ abstract class BaseFileStack extends BaseStacker {
                        throw new UnexpectedValueException(sprintf('data=%s does not have separator=0x%s at the end.',
                                $data,
                                dechex(BinaryFile::SEPARATOR_HEADER_ENTRIES)
-                       ));
+                       ), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
                }
 
                // Okay, then remove it
@@ -144,7 +145,7 @@ abstract class BaseFileStack extends BaseStacker {
                                $data,
                                count($header),
                                BinaryFile::HEADER_STACK_ELEMENT_COUNT
-                       ));
+                       ), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
                } elseif ($header[BinaryFile::HEADER_NAME_MAGIC] != StackableFile::STACK_MAGIC) {
                        // Bad magic
                        throw new InvalidMagicException($data, self::EXCEPTION_BAD_MAGIC);
@@ -155,7 +156,7 @@ abstract class BaseFileStack extends BaseStacker {
                                strlen($header[BinaryFile::HEADER_NAME_TOTAL_ENTRIES]),
                                $header[BinaryFile::HEADER_NAME_TOTAL_ENTRIES],
                                BinaryFile::LENGTH_COUNT
-                       ));
+                       ), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
                } elseif (strlen($header[BinaryFile::HEADER_NAME_SEEK_POSITION]) != BinaryFile::LENGTH_POSITION) {
                        // Position length not valid
                        throw new UnexpectedValueException(sprintf('header[%s](%d)=%s is not expected %d length',
@@ -163,7 +164,7 @@ abstract class BaseFileStack extends BaseStacker {
                                strlen($header[BinaryFile::HEADER_NAME_SEEK_POSITION]),
                                $header[BinaryFile::HEADER_NAME_SEEK_POSITION],
                                BinaryFile::LENGTH_POSITION
-                       ));
+                       ), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
                }
 
                // Decode count and seek position
@@ -322,7 +323,7 @@ abstract class BaseFileStack extends BaseStacker {
                        throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif ($this->isStackFull($stackerName)) {
                        // Stacker is full
-                       throw new FullStackerException([$this, $stackerName, $value], self::EXCEPTION_STACKER_IS_FULL);
+                       throw new BadMethodCallException(sprintf('stackerName=%s is full but method call.', $stackerName), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
                } elseif (is_resource($value) || is_object($value)) {
                        // Not wanted type
                        throw new InvalidArgumentException(sprintf('value[]=%s is not supported', gettype($value)));
@@ -332,6 +333,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.
                 */
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Invoking this->iteratorInstance->binaryFileInstance->writeValueToFile(%s,value[]=%s) ...', $stackerName, gettype($value)));
                $data = $this->getIteratorInstance()->getBinaryFileInstance()->writeValueToFile($stackerName, $value);
 
                // Add the hash and gap position to the index
@@ -359,11 +361,11 @@ abstract class BaseFileStack extends BaseStacker {
                        throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif ($this->isStackEmpty($stackerName)) {
                        // Throw an exception
-                       throw new BadMethodCallException([$this, $stackerName], self::EXCEPTION_STACKER_IS_EMPTY);
+                       throw new BadMethodCallException([$this, $stackerName], FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
                }
 
                // Now get the last value
-               /* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
+               /* NOISY-DEBUG: */ DebugMiddleware::getSelfInstance()->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
                $value = NULL;
 
                // Return it
@@ -387,11 +389,11 @@ abstract class BaseFileStack extends BaseStacker {
                        throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif ($this->isStackEmpty($stackerName)) {
                        // Throw an exception
-                       throw new BadMethodCallException([$this, $stackerName], self::EXCEPTION_STACKER_IS_EMPTY);
+                       throw new BadMethodCallException([$this, $stackerName], FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
                }
 
                // Now get the first value
-               /* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
+               /* NOISY-DEBUG: */ DebugMiddleware::getSelfInstance()->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
                $value = NULL;
 
                // Return it
@@ -415,11 +417,11 @@ abstract class BaseFileStack extends BaseStacker {
                        throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif ($this->isStackEmpty($stackerName)) {
                        // Throw an exception
-                       throw new BadMethodCallException([$this, $stackerName], self::EXCEPTION_STACKER_IS_EMPTY);
+                       throw new BadMethodCallException([$this, $stackerName], FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
                }
 
                // Now, remove the last entry, we don't care about the return value here, see elseif() block above
-               /* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
+               /* NOISY-DEBUG: */ DebugMiddleware::getSelfInstance()->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
                return NULL;
        }
 
@@ -439,11 +441,11 @@ abstract class BaseFileStack extends BaseStacker {
                        throw new InvalidArgumentException('Parameter "stackerName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                } elseif ($this->isStackEmpty($stackerName)) {
                        // Throw an exception
-                       throw new BadMethodCallException([$this, $stackerName], self::EXCEPTION_STACKER_IS_EMPTY);
+                       throw new BadMethodCallException([$this, $stackerName], FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
                }
 
                // Now, remove the last entry, we don't care about the return value here, see elseif() block above
-               /* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
+               /* NOISY-DEBUG: */ DebugMiddleware::getSelfInstance()->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
                return NULL;
        }
 
@@ -463,7 +465,7 @@ abstract class BaseFileStack extends BaseStacker {
                }
 
                // @TODO Please implement this, returning false
-               /* NOISY-DEBUG: */ $this->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
+               /* NOISY-DEBUG: */ DebugMiddleware::getSelfInstance()->partialStub('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName);
                $isFull = false;
 
                // Return result
@@ -503,7 +505,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -513,7 +515,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -567,7 +569,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -577,7 +579,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -588,7 +590,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -598,7 +600,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -609,7 +611,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -619,7 +621,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -629,7 +631,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()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -643,7 +645,7 @@ abstract class BaseFileStack extends BaseStacker {
         */
        public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
                // Not supported
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -656,7 +658,7 @@ abstract class BaseFileStack extends BaseStacker {
         */
        public function writeAtPosition (int $seekPosition, string $dataStream) {
                // Not supported
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -668,7 +670,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
        public function writeValueToFile (string $stackName, $value) {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -681,7 +683,7 @@ abstract class BaseFileStack extends BaseStacker {
         */
        public function searchNextGap (int $length) {
                // Not supported here
-               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+               throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getBinaryFileInstance()), FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
        /**
@@ -743,7 +745,7 @@ abstract class BaseFileStack extends BaseStacker {
                                gettype($gapPosition),
                                $gapPosition,
                                $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()
-                       ));
+                       ), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
                }
 
                // Then write the data at that gap