Refacuring / possible WIP:
authorRoland Häder <roland@mxchange.org>
Thu, 10 Dec 2020 01:37:41 +0000 (02:37 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 10 Dec 2020 01:37:41 +0000 (02:37 +0100)
- rewrote a lot clases and cleared up abuse of Block interface
- got rid of $applicationInstance as this can be retrieved singelton
- moved some files, added new BaseFileIndex class

Signed-off-by: Roland Häder <roland@mxchange.org>
41 files changed:
framework/config-global.php
framework/main/classes/class_BaseFrameworkSystem.php
framework/main/classes/commands/class_BaseCommand.php
framework/main/classes/commands/html/class_HtmlConfirmCommand.php
framework/main/classes/commands/html/class_HtmlHomeCommand.php
framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php
framework/main/classes/commands/html/class_HtmlLoginCommand.php
framework/main/classes/commands/html/class_HtmlLoginFailedCommand.php
framework/main/classes/commands/html/class_HtmlLogoutDoneCommand.php
framework/main/classes/commands/html/class_HtmlRegisterCommand.php
framework/main/classes/commands/html/class_HtmlStatusCommand.php
framework/main/classes/database/result/class_CachedDatabaseResult.php
framework/main/classes/file_directories/binary/class_BaseBinaryFile.php
framework/main/classes/file_directories/binary/index/class_IndexFile.php
framework/main/classes/file_directories/binary/stack/class_StackFile.php
framework/main/classes/file_directories/class_BaseFileIo.php
framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php
framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php
framework/main/classes/index/class_BaseIndex.php
framework/main/classes/index/file/class_BaseFileIndex.php [new file with mode: 0644]
framework/main/classes/index/file/stack/class_FileStackIndex.php [new file with mode: 0644]
framework/main/classes/index/file_stack/class_FileStackIndex.php [deleted file]
framework/main/classes/iterator/file/class_FileIterator.php
framework/main/classes/output/console/class_ConsoleOutput.php
framework/main/classes/output/debug/class_BaseDebugOutput.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/index/class_Indexable.php
framework/main/interfaces/index/file/class_FileIndexer.php [new file with mode: 0644]
framework/main/interfaces/index/file/stack/class_IndexableStack.php [new file with mode: 0644]
framework/main/interfaces/index/stack/class_IndexableStack.php [deleted file]
framework/main/interfaces/io/class_Streamable.php
framework/main/interfaces/io/class_StreamableInput.php
framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php
framework/main/interfaces/stacker/file/class_StackableFile.php
framework/main/middleware/io/class_FileIoHandler.php
framework/main/traits/index/stack/class_IndexableStackTrait.php [deleted file]

index d22cbf83af67ae82c57d22b915b90414223656c5..90548cb884b36f18cd75b35321f9ed8fd94b3b32 100644 (file)
@@ -386,7 +386,7 @@ $cfg->setConfigEntry('file_stack_pre_allocate_enabled', 'Y');
 $cfg->setConfigEntry('file_stack_pre_allocate_count', 10000);
 
 // CFG: INDEX-INDEX-CLASS
-$cfg->setConfigEntry('file_stack_index_class', 'Org\Mxchange\CoreFramework\Index\Stack\FileStackIndex');
+$cfg->setConfigEntry('file_stack_index_class', 'Org\Mxchange\CoreFramework\Index\File\Stack\FileStackIndex');
 
 // CFG: INDEX-PRE-ALLOCATE-ENABLED
 $cfg->setConfigEntry('index_pre_allocate_enabled', 'Y');
index e9ce996fe89890f8dea7bb437113e5d2ab07fc8f..6810e7244d653fb908b8accf5138b3e2ffdb4190 100644 (file)
@@ -1639,11 +1639,8 @@ Loaded includes:
         * @return      void
         */
        protected function initWebOutputInstance () {
-               // Get application instance
-               $applicationInstance = ApplicationHelper::getSelfInstance();
-
                // Init web output instance
-               $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
+               $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
 
                // Set it locally
                $this->setWebOutputInstance($outputInstance);
index 49c357b89ac60d23c19af742193bb1edfdf1c738..8eba066cf591692d43d638bd3cec89116a79f1cb 100644 (file)
@@ -117,7 +117,7 @@ abstract class BaseCommand extends BaseFrameworkSystem {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName($applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName() . '_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName($applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName() . '_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index aeea7318601dbdcec227065ef76e0aa71bb0e428..f86850e2ce736f993045b502e6ad7fa61c32a487 100644 (file)
@@ -125,7 +125,7 @@ class HtmlConfirmCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('confirm_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('confirm_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index ff1a09329d8f176024ade6f92d6f5e0789445e7b..c1135e67c5ebcf81f3767e0fa9f1107141328bc5 100644 (file)
@@ -110,7 +110,7 @@ class HtmlHomeCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('home_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('home_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index f5123a7ac880f08e7528f1ef00ebf254b0bf87f1..ba9ed0f6c3bdec1c2ee39cffc0734800637c93c3 100644 (file)
@@ -148,7 +148,7 @@ class HtmlLoginAreaCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index ce67a7909c9e0124ba51c9882b70e47974bf0455..bdd662e0b5975f539f13c24c56510caf6f438c95 100644 (file)
@@ -115,7 +115,7 @@ class HtmlLoginCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('login_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('login_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index aff6ccc3adce72430a56434af0b66b35fbff7596..fb8896813a3d0b40f21805720cdcc597eaea2a1d 100644 (file)
@@ -112,7 +112,7 @@ class HtmlLoginFailedCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('login_failed_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('login_failed_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index 682a22a6e93a63e4d1b9fad1561233a57420252c..49763ff36d2d334806bed6854683008ea6906012 100644 (file)
@@ -112,7 +112,7 @@ class HtmlLogoutDoneCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('logout_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('logout_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index fa9aa755110a473e29ad95577b2ca7b2c26c29ef..01128abfd79dd993bb4c65e338d49650eae14edb 100644 (file)
@@ -116,7 +116,7 @@ class HtmlRegisterCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('register_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('register_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index 1b42190f28f2cd4bd912bf44449b4cbe53637490..3e6ae8aa150e1a97c9181daf98794d6d9ba3d015 100644 (file)
@@ -109,7 +109,7 @@ class HtmlStatusCommand extends BaseCommand implements Commandable {
 
                // Construct the menu in every command. We could do this in BaseCommand class. But this means
                // *every* command has a navigation system and that is want we don't want.
-               $menuInstance = ObjectFactory::createObjectByConfiguredName('status_menu_class', array($applicationInstance));
+               $menuInstance = ObjectFactory::createObjectByConfiguredName('status_menu_class');
 
                // Render the menu
                $menuInstance->renderMenu();
index 747660386c1e29384599f21e9ca3e84102d43e16..9b59813bb9da9944c34f184a42f549c20dbbf6c0 100644 (file)
@@ -14,6 +14,7 @@ use Org\Mxchange\CoreFramework\Result\Update\UpdateableResult;
 
 // Import SPL stuff
 use \InvalidArgumentException;
+use \OutOfBoundsException;
 use \SeekableIterator;
 
 /**
@@ -171,15 +172,22 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
        /**
         * Seeks for to a specified position
         *
-        * @param       $index  Index to seek for
+        * @param       $seekPosition   Position to seek to
         * @return      void
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
-       public function seek (int $index) {
+       public function seek (int $seekPosition) {
+               // Validate parameter
+               if ($seekPosition < 0) {
+                       // Throw exception
+                       throw new OutOfBoundsException(sprintf('seekPositon=%d is not seekable', $seekPosition));
+               }
+
                // Rewind to beginning
                $this->rewind();
 
                // Search for the entry
-               while (($this->currentPos < $index) && ($this->valid())) {
+               while (($this->currentPos < $seekPosition) && ($this->valid())) {
                        // Continue on
                        $this->next();
                }
index fb96ae762645c10d670eb39d45048aeaceaa0aba..95c642eb066f72b4330566218d486794b351fdea 100644 (file)
@@ -6,18 +6,17 @@ namespace Org\Mxchange\CoreFramework\Filesystem\File;
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
-use Org\Mxchange\CoreFramework\Filesystem\Block;
-use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
 use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
+use Org\Mxchange\CoreFramework\Index\Indexable;
 use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
-use Org\Mxchange\CoreFramework\Traits\Index\Stack\IndexableStackTrait;
+use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
 use Org\Mxchange\CoreFramework\Traits\Stack\StackableTrait;
 
 // Import SPL stuff
 use \BadMethodCallException;
 use \InvalidArgumentException;
 use \LogicException;
+use \OutOfBoundsException;
 use \SplFileInfo;
 use \UnexpectedValueException;
 
@@ -46,7 +45,7 @@ use \UnexpectedValueException;
 abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
        // Load traits
        use StackableTrait;
-       use IndexableStackTrait;
+       use IndexableTrait;
 
        /**
         * Separator for header data
@@ -501,6 +500,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         * @param       $data                   Data to be written
         * @param       $flushHeader    Whether to flush the header (default: flush)
         * @return      void
+        * @throws      OutOfBoundsException    If the position is not seekable
         * @throws      InvalidArgumentException        If a parameter is invalid
         */
        public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
@@ -508,7 +508,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader)));
                if ($seekPosition < 0) {
                        // Invalid seek position
-                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
                } elseif (empty($data)) {
                        // Empty data is invalid, too
                        throw new InvalidArgumentException('Parameter "data" is empty');
@@ -548,6 +548,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         * @param       $seekPosition   Seek position in file
         * @param       $dataStream             Data to be written
         * @return      mixed                   Number of writes bytes or false on error
+        * @throws      OutOfBoundsException    If the position is not seekable
         * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function writeAtPosition (int $seekPosition, string $dataStream) {
@@ -555,7 +556,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                /* 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));
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
                } elseif (empty($dataStream)) {
                        // Empty dataStream
                        throw new InvalidArgumentException('Parameter "dataStream" is empty');
@@ -681,7 +682,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
 
                // Calculate minimum length for one entry and get file size
-               $minimumBlockLength = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+               $minimumBlockLength = $this->getIndexInstance()->calculateMinimumBlockLength();
                $fileSize = $this->getFileSize();
 
                // Calulcate seek position
@@ -733,14 +734,14 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         * @param       $offset         Offset to seek to (or used as "base" for other seeks)
         * @param       $whence         Added to offset (default: only use offset to seek to)
         * @return      $status         Status of file seek: 0 = success, -1 = failed
-        * @throws      InvalidArgumentException         If a parameter is not valid
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
        public function seek (int $offset, int $whence = SEEK_SET) {
                // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: offset=%d,whence=%d - CALLED!', $offset, $whence));
                if ($offset < 0) {
                        // No offset is smaller than zero
-                       throw new InvalidArgumentException(sprintf('offset=%d is not valid', $offset));
+                       throw new OutOfBoundsException(sprintf('offset=%d is not valid', $offset));
                }
 
                // Call pointer instance
@@ -756,14 +757,14 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         *
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
-        * @throws      InvalidArgumentException         If a parameter is not valid
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
        public function read (int $bytes = 0) {
                // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: bytes=%d - CALLED!', $bytes));
                if ($bytes < 0) {
-                       // Throw IAE
-                       throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+                       // Throw exception
+                       throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
                }
 
                // Call pointer instance
@@ -888,7 +889,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
 
                // First calculate minimum block length
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d', $this->determineSeekPosition()));
-               $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+               $length = $this->getIndexInstance()->calculateMinimumBlockLength();
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
 
                // Read possibly back-buffered bytes from previous call of next().
@@ -966,7 +967,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
        public function isValid () {
                // First calculate minimum block length
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+               $length = $this->getIndexInstance()->calculateMinimumBlockLength();
 
                // Short be more than zero!
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
@@ -1014,17 +1015,17 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
        public function readFileHeader () {
                // Is index set or stack?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               if ($this->getIndexableStackInstance() instanceof IndexableStack) {
+               if ($this->getIndexInstance() instanceof Indexable) {
                        // Call index instance
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexableStackInstance->readFileHeader() ...');
-                       $this->getIndexableStackInstance()->readFileHeader();
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexInstance->readIndexHeader() ...');
+                       $this->getIndexInstance()->readIndexHeader();
                } elseif ($this->getStackInstance() instanceof StackableFile) {
                        // Call stacke instance
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->stackInstance->readFileHeader() ...');
-                       $this->getStackInstance()->readFileHeader();
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->stackInstance->readStackHeader() ...');
+                       $this->getStackInstance()->readStackHeader();
                } else {
                        // Bad logic?
-                       throw new LogicException('Wether indexableStackInstance nor stackableFileInstance are set');
+                       throw new LogicException('Wether indexInstance nor stackInstance are set');
                }
 
                // Trace message
@@ -1039,7 +1040,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
        public function flushFileHeader () {
                // Call block instance
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               $this->getIndexableStackInstance()->flushFileHeader();
+               $this->getIndexInstance()->flushFileHeader();
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
index 010927136fd069a19bc37b933c2b75278462cc7f..473ba3140cc03818613df5d1c0d8ccf820d2a279 100644 (file)
@@ -6,7 +6,7 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Index;
 use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
 use Org\Mxchange\CoreFramework\Filesystem\Index\IndexableFile;
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
+use Org\Mxchange\CoreFramework\Index\File\Stack\Indexable;
 
 // Import SPL stuff
 use \SplFileInfo;
@@ -48,16 +48,16 @@ class IndexFile extends BaseBinaryFile implements IndexableFile {
         * Creates an instance of this File class and prepares it for usage
         *
         * @param       $fileInfoInstance       An instance of a SplFileInfo class
-        * @param       $indexInstance  An instance of a IndexableStack class
+        * @param       $indexInstance  An instance of a Indexable class
         * @return      $indexFileInstance      An instance of an IndexableFile class
         */
-       public final static function createIndexFile (SplFileInfo $fileInfoInstance, IndexableStack $indexInstance) {
+       public final static function createIndexFile (SplFileInfo $fileInfoInstance, Indexable $indexInstance) {
                // Get a new instance
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,indexInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $indexInstance->__toString()));
                $indexFileInstance = new IndexFile();
 
                // Set file instance here for callbacks
-               $indexFileInstance->setIndexableStackInstance($indexInstance);
+               $indexFileInstance->setIndexInstance($indexInstance);
 
                // Expand file name with .idx
                $indexInfoInstance = new SplFileInfo(sprintf('%s.idx', $fileInfoInstance->__toString()));
@@ -73,27 +73,49 @@ class IndexFile extends BaseBinaryFile implements IndexableFile {
        /**
         * Writes given value to the file and returns a hash and gap position for it
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $value          Value to be added to the stack
         * @return      $data           Hash and gap position
-        * @throws      UnsupportedOperationException   If this method is called
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function writeValueToFile (string $groupId, $value) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: groupId=' . $groupId . ',value[' . gettype($value) . ']=' . print_r($value, true));
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+       public function writeValueToFile (string $stackName, $value) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
+               if (empty($stackName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "stackName" is empty');
+               } elseif (is_object($value) || is_resource($value)) {
+                       // Not wanted here
+                       throw new InvalidArgumentException(sprintf('value[]=%s is not stackable in files', gettype($value)));
+               }
+
+               // Encode/convert the value into a "binary format"
+               $encoded = StringUtils::encodeData($value);
+
+               // Get a strong hash for the "encoded" data
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: encoded=%s', $encoded));
+               $hash = self::hash($encoded);
+
+               // Then write it to the next free gap
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: hash=%s', $hash));
+               $data = $this->getIndexInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
+
+               // Return info
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: data[]=%s - EXIT!', gettype($data)));
+               return $data;
        }
 
        /**
         * Writes given raw data to the file and returns a gap position and length
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $hash           Hash from encoded value
         * @param       $encoded        Encoded value to be written to the file
         * @return      $data           Gap position and length of the raw data
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: groupId=' . $groupId . ',encoded()=' . strlen($encoded));
+       public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
index 2cd5dde0c62edad2e84be1cb2a7393893b9728f4..46cc8b326ad46a3898afbf83d7eda874b029f965 100644 (file)
@@ -72,17 +72,17 @@ class StackFile extends BaseBinaryFile implements FileStacker {
        /**
         * Writes given value to the file and returns a hash and gap position for it
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $value          Value to be added to the stack
         * @return      $data           Hash and gap position
         * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function writeValueToFile (string $groupId, $value) {
+       public function writeValueToFile (string $stackName, $value) {
                // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: groupId=%s,value[]=%s - CALLED!', $groupId, gettype($value)));
-               if (empty($groupId)) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
+               if (empty($stackName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "groupId" is empty');
+                       throw new InvalidArgumentException('Parameter "stackName" is empty');
                } elseif (is_object($value) || is_resource($value)) {
                        // Not wanted here
                        throw new InvalidArgumentException(sprintf('value[]=%s is not stackable in files', gettype($value)));
@@ -95,7 +95,7 @@ class StackFile extends BaseBinaryFile implements FileStacker {
                $hash = self::hash($encoded);
 
                // Then write it to the next free gap
-               $data = $this->getStackInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
+               $data = $this->getStackInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
 
                // Return info
                return $data;
@@ -104,14 +104,14 @@ class StackFile extends BaseBinaryFile implements FileStacker {
        /**
         * Writes given raw data to the file and returns a gap position and length
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $hash           Hash from encoded value
         * @param       $encoded        Encoded value to be written to the file
         * @return      $data           Gap position and length of the raw data
         * @throws      UnsupportedOperationException   If this method is called
         */
-       public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: groupId=' . $groupId . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
+       public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
index c1c716629456066604165c140c144e66757b9547..6036db008de5d709114d3ba7add8fb7350ccb9ee 100644 (file)
@@ -9,7 +9,7 @@ use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
 // Import SPL stuff
-use \InvalidArgumentException;
+use \OutOfBoundsException;
 use \SplFileObject;
 
 /**
@@ -157,8 +157,8 @@ abstract class BaseFileIo extends BaseFrameworkSystem implements FilePointer, Cl
                // 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));
+                       // Throw exception
+                       throw new OutOfBoundsException(sprintf('offset=%d is not valid', $offset));
                }
 
                // Seek to position
index eef4a749e0ce16e1e6f2144f26f0cfbcb5de9858..620b2f31d2d205ad8d96e7c55194deef1e0ecf13 100644 (file)
@@ -117,14 +117,15 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer {
         *
         * @param       $bytes  Amount of bytes to read or whole line (only text files)
         * @return      $data   Data read from file
+        * @throws      OutOfBoundsException    If the position is not seekable
         * @throws      NullPointerException    If the file pointer instance is not set by setFileObject()
-        * @throws      InvalidResourceException        If there is no object being set
+        * @throws      LogicException  If $fileObject is not an object
         */
        public function read (int $bytes = 0) {
                // Some sanity checks
                if ($bytes < 0) {
                        // Cannot be below zero
-                       throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+                       throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
                } elseif (is_null($this->getFileObject())) {
                        // Pointer not initialized
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
index ff58e65e4eb02955d9e4e3476e00c7811522f0c6..ce728050da4668e9bc233984d4b08018c1ba06d7 100644 (file)
@@ -15,6 +15,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 // Import SPL stuff
 use \InvalidArgumentException;
 use \SplFileInfo;
+use \OutOfBoundsException;
 use \UnexpectedValueException;
 
 /**
@@ -146,6 +147,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         * @param       $seekPosition   Seek position in file
         * @param       $dataStream             Data to be written
         * @return      mixed                   Number of writes bytes or false on error
+        * @throws      OutOfBoundsException    If the position is not seekable
         * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function writeAtPosition (int $seekPosition, string $dataStream) {
@@ -153,7 +155,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: 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));
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
                } elseif (empty($dataStream)) {
                        // Empty dataStream
                        throw new InvalidArgumentException('Parameter "dataStream" is empty');
@@ -191,14 +193,14 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         * @param       $seekPosition   Seek position in file
         * @param       $whence                 "Seek mode" (see http://de.php.net/fseek)
         * @return      $status                 Status of this operation
-        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
        public function seek (int $seekPosition, int $whence = SEEK_SET) {
                // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
                if ($seekPosition < 0) {
                        // Invalid seek position
-                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
                }
 
                // Move the file pointer
@@ -229,14 +231,14 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         *
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
-        * @throws      InvalidArgumentException        If a parameter is invalid
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
        public function read (int $bytes = 0) {
                // Validatre parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: bytes=%d - CALLED!', $bytes));
                if ($bytes < 0) {
                        // Bytes cannot be lesser than zero
-                       throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+                       throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
                }
 
                // Is $bytes bigger than zero?
index 5e56d1dc1c7222add6bd3e6a6a486cb591d80046..fe369b742cd2106557bd65059b078703544fa6c2 100644 (file)
@@ -58,333 +58,14 @@ abstract class BaseIndex extends BaseFrameworkSystem implements Indexable {
        }
 
        /**
-        * Reads the file header
+        * Checks if this index has been fully and properly loaded.
         *
-        * @return      void
-        * @throws      UnexpectedValueException        If header length or count of elements is invalid
+        * @return      $isLoaded       Whether this index has been loaded
         */
-       public function readFileHeader () {
-               // First rewind to beginning as the header sits at the beginning ...
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
-               $this->getIteratorInstance()->rewind();
-
-               // Then read it (see constructor for calculation)
-               $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
-
-               // Have all requested bytes been read?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
-               if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
-                       // Invalid header length
-                       throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d',
-                               strlen($data),
-                               $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"',
-                               $data,
-                               chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
-                       ));
-               }
-
-               // Okay, then remove it
-               $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();
-
-               /*
-                * Now split it:
-                *
-                * 0 => magic
-                * 1 => total entries
-                */
-               $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data);
-
-               // Check if the array has only 3 elements
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: header()=%d', count($header)));
-               //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: header(%d)=%s', count($header), print_r($header, true)));
-               if (count($header) != 2) {
-                       // Bad header
-                       throw new UnexpectedValueException(sprintf('header()=%d is not expected value 2', count($header)));
-               } elseif ($header[0] !== Indexable::INDEX_MAGIC) {
-                       // Magic must be in first element
-                       throw new UnexpectedValueException(sprintf('header[0]=%s is not the expected magic (%s)', $header[0], Indexable::INDEX_MAGIC));
-               } elseif (strlen($header[1]) != BaseBinaryFile::LENGTH_COUNT) {
-                       // Length of total entries not matching
-                       throw new UnexpectedValueException(sprintf('header[1](%d)=%s does not have expected length %d', strlen($header[1]), $header[1], BaseBinaryFile::LENGTH_COUNT));
-               }
-
-               // Decode count
-               $header[1] = hex2bin($header[1]);
-
-               // Set it here
-               $this->getIteratorInstance()->setHeader($header);
-
+       public function isIndexLoaded () {
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
-       }
-
-       /**
-        * Flushes the file header
-        *
-        * @return      void
-        */
-       public function flushFileHeader () {
-               // Put all informations together
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
-               $header = sprintf('%s%s%s%s',
-                       // Magic
-                       Indexable::INDEX_MAGIC,
-
-                       // Separator header data
-                       chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
-
-                       // Total entries
-                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
-
-                       // Separator header<->entries
-                       chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
-               );
-
-               // Write it to disk (header is always at seek position 0)
-               /* 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!');
-       }
-
-       /**
-        * Initializes this index
-        *
-        * @param       $fileInfoInstance       An instance of a SplFileInfo class
-        * @return      void
-        * @todo        Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file.
-        */
-       protected function initIndex (SplFileInfo $fileInfoInstance) {
-               // Get a file i/o pointer instance for index file
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
-               $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
-
-               // Get iterator instance
-               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', [$fileInstance]);
-
-               // Set iterator here
-               $this->setIteratorInstance($iteratorInstance);
-
-               // Calculate header size
-               $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()) {
-                       // 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();
-
-                       // Mark as freshly created
-                       $created = true;
-               }
-
-               // Load the file header
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->readFileHeader() ...');
-               $this->readFileHeader();
-
-               // Freshly created?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: created=%d', intval($created)));
-               if (!$created) {
-                       // Analyze file structure
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...');
-                       $this->getIteratorInstance()->analyzeFileStructure();
-               }
-
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
-       }
-
-       /**
-        * Calculates minimum length for one entry/block
-        *
-        * @return      $length         Minimum length for one entry/block
-        */
-       public function calculateMinimumBlockLength () {
-               // Is it "cached"?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
-               if (self::$minimumBlockLength == 0) {
-                       // Calulcate it
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calculating ...');
-                       self::$minimumBlockLength = (
-                               // Type
-                               BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) +
-                               // Position
-                               BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES))
-                       );
-               }
-
-               // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: self::minimumBlockLength=%d - EXIT!', self::$minimumBlockLength));
-               return self::$minimumBlockLength;
-       }
-
-       /**
-        * Determines whether the EOF has been reached
-        *
-        * @return      $isEndOfFileReached             Whether the EOF has been reached
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function isEndOfFileReached () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Initializes counter for valid entries, arrays for damaged entries and
-        * an array for gap seek positions. If you call this method on your own,
-        * please re-analyze the file structure. So you are better to call
-        * analyzeFileStructure() instead of this method.
-        *
-        * @return      void
-        * @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);
-       }
-
-       /**
-        * Getter for header size
-        *
-        * @return      $totalEntries   Size of file header
-        * @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);
-       }
-
-       /**
-        * Setter for header size
-        *
-        * @param       $headerSize             Size of file header
-        * @return      void
-        * @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);
-       }
-
-       /**
-        * Getter for header array
-        *
-        * @return      $totalEntries   Size of file header
-        * @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);
-       }
-
-       /**
-        * Setter for header
-        *
-        * @param       $header         Array for a file header
-        * @return      void
-        * @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);
-       }
-
-       /**
-        * Updates seekPosition attribute from file to avoid to much access on file.
-        *
-        * @return      void
-        * @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);
-       }
-
-       /**
-        * Getter for total entries
-        *
-        * @return      $totalEntries   Total entries in this file
-        * @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);
-       }
-
-       /**
-        * "Getter" for file size
-        *
-        * @return      $fileSize       Size of currently loaded file
-        */
-       public function getFileSize () {
-               // Call iterator's method
-               return $this->getIteratorInstance()->getFileSize();
-       }
-
-       /**
-        * Writes data at given position
-        *
-        * @param       $seekPosition   Seek position
-        * @param       $data                   Data to be written
-        * @param       $flushHeader    Whether to flush the header (default: flush)
-        * @return      void
-        * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
-        */
-       public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('seekPosition=%s,data[]=%s,flushHeader=%d - CALLED!', $seekPosition, gettype($data), intval($flushHeader)));
-               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
-        *
-        * @param       $groupId        Group identifier
-        * @param       $value          Value to be added to the stack
-        * @return      $data           Hash and gap position
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function writeValueToFile (string $groupId, $value) {
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('groupId=%s,value[%s]=%s - CALLED!', $groupId, gettype($value), print_r($value, true)));
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Writes given raw data to the file and returns a gap position and length
-        *
-        * @param       $groupId        Group identifier
-        * @param       $hash           Hash from encoded value
-        * @param       $encoded        Encoded value to be written to the file
-        * @return      $data           Gap position and length of the raw data
-        */
-       public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('groupId=%s,hash=%s,encoded()=%d - CALLED!', $groupId, $hash, strlen($encoded)));
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+               /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
        }
 
 }
diff --git a/framework/main/classes/index/file/class_BaseFileIndex.php b/framework/main/classes/index/file/class_BaseFileIndex.php
new file mode 100644 (file)
index 0000000..7088750
--- /dev/null
@@ -0,0 +1,315 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
+use Org\Mxchange\CoreFramework\Index\BaseIndex;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
+
+// Import SPL stuff
+use \OutOfBoundsException;
+use \SplFileInfo;
+use \UnexpectedValueException;
+
+/**
+ * A general file-based index class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Reads the file header
+        *
+        * @return      void
+        * @throws      UnexpectedValueException        If header length or count of elements is invalid
+        */
+       public function readIndexHeader () {
+               // First rewind to beginning as the header sits at the beginning ...
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+               $this->getIteratorInstance()->rewind();
+
+               // Then read it (see constructor for calculation)
+               $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+
+               // Have all requested bytes been read?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
+               if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
+                       // Invalid header length
+                       throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d',
+                               strlen($data),
+                               $data,
+                               $this->getIteratorInstance()->getHeaderSize()
+                       ));
+               } elseif (empty(trim($data, chr(0)))) {
+                       // Empty file header
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-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"',
+                               $data,
+                               chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
+                       ));
+               }
+
+               // Okay, then remove it
+               $data = substr($data, 0, -1);
+
+               // And update seek position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->updateSeekPosition() ...');
+               $this->getIteratorInstance()->updateSeekPosition();
+
+               /*
+                * Now split it:
+                *
+                * 0 => magic
+                * 1 => total entries
+                */
+               $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data);
+
+               // Check if the array has only 3 elements
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: header()=%d', count($header)));
+               //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: header(%d)=%s', count($header), print_r($header, true)));
+               if (count($header) != 2) {
+                       // Bad header
+                       throw new UnexpectedValueException(sprintf('header()=%d is not expected value 2', count($header)));
+               } elseif ($header[0] !== Indexable::INDEX_MAGIC) {
+                       // Magic must be in first element
+                       throw new UnexpectedValueException(sprintf('header[0]=%s is not the expected magic (%s)', $header[0], Indexable::INDEX_MAGIC));
+               } elseif (strlen($header[1]) != BaseBinaryFile::LENGTH_COUNT) {
+                       // Length of total entries not matching
+                       throw new UnexpectedValueException(sprintf('header[1](%d)=%s does not have expected length %d', strlen($header[1]), $header[1], BaseBinaryFile::LENGTH_COUNT));
+               }
+
+               // Decode count
+               $header[1] = hex2bin($header[1]);
+
+               // Set it here
+               $this->getIteratorInstance()->setHeader($header);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
+       }
+
+       /**
+        * Flushes the file header
+        *
+        * @return      void
+        */
+       public function flushFileHeader () {
+               // Put all informations together
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+               $header = sprintf('%s%s%s%s',
+                       // Magic
+                       Indexable::INDEX_MAGIC,
+
+                       // Separator header data
+                       chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
+
+                       // Total entries
+                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
+
+                       // Separator header<->entries
+                       chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
+               );
+
+               // Write it to disk (header is always at seek position 0)
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header));
+               $this->getIteratorInstance()->writeAtPosition(0, $header);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
+       }
+
+       /**
+        * Initializes this index
+        *
+        * @param       $fileInfoInstance       An instance of a SplFileInfo class
+        * @return      void
+        * @todo        Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file.
+        */
+       protected function initIndex (SplFileInfo $fileInfoInstance) {
+               // Get a file i/o pointer instance for index file
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
+               $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
+
+               // Get iterator instance
+               $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', [$fileInstance]);
+
+               // Set iterator here
+               $this->setIteratorInstance($iteratorInstance);
+
+               // Calculate header size
+               $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-FILE-INDEX: Setting headerSize=%d ...', $headerSize));
+               $this->getIteratorInstance()->setHeaderSize($headerSize);
+
+               // Init counters and gaps array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->initCountersGapsArray() ...');
+               $this->getIteratorInstance()->initCountersGapsArray();
+
+               // Default is not created
+               $created = false;
+
+               // Is the file's header initialized?
+               if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
+                       // First pre-allocate a bit
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->preAllocateFile(index) ...');
+                       $this->getIteratorInstance()->preAllocateFile('index');
+
+                       // Then write file header
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->createFileHeader() ...');
+                       $this->getIteratorInstance()->createFileHeader();
+
+                       // Mark as freshly created
+                       $created = true;
+               }
+
+               // Load the file header
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->readIndexHeader() ...');
+               $this->readIndexHeader();
+
+               // Freshly created?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: created=%d', intval($created)));
+               if (!$created) {
+                       // Analyze file structure
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...');
+                       $this->getIteratorInstance()->analyzeFileStructure();
+               }
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
+       }
+
+       /**
+        * Calculates minimum length for one entry/block
+        *
+        * @return      $length         Minimum length for one entry/block
+        */
+       public function calculateMinimumBlockLength () {
+               // Is it "cached"?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+               if (self::$minimumBlockLength == 0) {
+                       // Calulcate it
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calculating ...');
+                       self::$minimumBlockLength = (
+                               // Type
+                               BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) +
+                               // Position
+                               BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES))
+                       );
+               }
+
+               // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: self::minimumBlockLength=%d - EXIT!', self::$minimumBlockLength));
+               return self::$minimumBlockLength;
+       }
+
+       /**
+        * "Getter" for file size
+        *
+        * @return      $fileSize       Size of currently loaded file
+        */
+       public function getFileSize () {
+               // Call iterator's method
+               return $this->getIteratorInstance()->getFileSize();
+       }
+
+       /**
+        * Searches for next suitable gap the given length of data can fit in
+        * including padding bytes.
+        *
+        * @param       $length                 Length of raw data
+        * @return      $seekPosition   Found next gap's seek position
+        * @throws      InvalidArgumentException        If the parameter is not valid
+        * @todo        Unfinished work
+        */
+       public function searchNextGap (int $length) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: length=%d - CALLED!', $length));
+               if ($length <= 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
+               }
+
+               // Partial stub!
+               $this->partialStub('length=' . $length);
+       }
+
+       /**
+        * 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      OutOfBoundsException    If the position is not seekable
+        * @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-FILE-INDEX: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
+               if ($seekPosition < 0) {
+                       // Invalid seek position
+                       throw new OutOfBoundsException(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('BASE-FILE-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('BASE-FILE-INDEX: status[%s]=%d - EXIT!', gettype($status), $status));
+               return $status;
+       }
+
+       /**
+        * Checks if this index has been fully and properly loaded.
+        *
+        * @return      $isLoaded       Whether this index has been loaded
+        */
+       public function isIndexLoaded () {
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+               /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
+       }
+
+}
diff --git a/framework/main/classes/index/file/stack/class_FileStackIndex.php b/framework/main/classes/index/file/stack/class_FileStackIndex.php
new file mode 100644 (file)
index 0000000..db2e7d4
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File\Stack;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
+use Org\Mxchange\CoreFramework\Index\File\BaseFileIndex;
+use Org\Mxchange\CoreFramework\Index\File\Stack\IndexableStack;
+use Org\Mxchange\CoreFramework\Index\Indexable;
+use Org\Mxchange\CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+use \SplFileInfo;
+use \UnexpectedValueException;
+
+/**
+ * A FileStack index class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class FileStackIndex extends BaseFileIndex implements IndexableStack, Registerable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this Index class and prepares it for usage
+        *
+        * @param       $fileInfoInstance       An instance of a SplFileInfo class
+        * @return      $indexInstance  An instance of this Index class
+        */
+       public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
+               // Get a new instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
+               $indexInstance = new FileStackIndex();
+
+               // Initialize index
+               $indexInstance->initIndex($fileInfoInstance);
+
+               // Return the prepared instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: indexInstance=%s - EXIT!', $indexInstance->__toString()));
+               return $indexInstance;
+       }
+
+       /**
+        * Adds given data's hash to an index file
+        *
+        * @param       $stackName      Name of stack to add hash for
+        * @param       $data           Hash and gap position to be added to the index
+        * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If an invalid gap position is being returned
+        */
+       public function addHashedDataToIndex (string $stackName, array $data) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,data()=%d - CALLED!', $stackName, count($data)));
+               if (empty($stackName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "stackName" is empty');
+               } elseif (count($data) == 0) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "data" is an empty array');
+               } elseif (!isset($data[StackableFile::ARRAY_NAME_HASH])) {
+                       // Important array element missing
+                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_HASH]));
+               } elseif (!isset($data[StackableFile::ARRAY_NAME_GAP_POSITION])) {
+                       // Important array element missing
+                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_GAP_POSITION]));
+               } elseif (!isset($data[StackableFile::ARRAY_NAME_DATA_LENGTH])) {
+                       // Important array element missing
+                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_DATA_LENGTH]));
+               }
+
+               // Raw data been written to the file
+               $rawData = sprintf('%s%s%s%s%s%s%s',
+                       $stackName,
+                       Indexable::SEPARATOR_GROUP_HASH,
+                       hex2bin($data[StackableFile::ARRAY_NAME_HASH]),
+                       Indexable::SEPARATOR_HASH_GAP_POSITION,
+                       $data[StackableFile::ARRAY_NAME_GAP_POSITION],
+                       Indexable::SEPARATOR_GAP_LENGTH,
+                       $data[StackableFile::ARRAY_NAME_DATA_LENGTH]
+               );
+
+               // Search for next free gap
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,hash=%s,rawData()=%d', $stackName, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
+               $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
+
+               // 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)) {
+                       // 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)));
+               }
+
+               // Then write the data at that gap
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: Calling this->iteratorInstance->writeData(%d,%s) ...', $gapPosition, $rawData));
+               $this->getIteratorInstance()->writeData($gapPosition, $rawData);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,hash=%s,rawData()=%d - EXIT!', $stackName, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
+       }
+
+}
diff --git a/framework/main/classes/index/file_stack/class_FileStackIndex.php b/framework/main/classes/index/file_stack/class_FileStackIndex.php
deleted file mode 100644 (file)
index 5e399b8..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Index\Stack;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
-use Org\Mxchange\CoreFramework\Index\BaseIndex;
-use Org\Mxchange\CoreFramework\Index\Indexable;
-use Org\Mxchange\CoreFramework\Registry\Registerable;
-use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
-
-// Import SPL stuff
-use \InvalidArgumentException;
-use \SplFileInfo;
-use \UnexpectedValueException;
-
-/**
- * A FileStack index class
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this Index class and prepares it for usage
-        *
-        * @param       $fileInfoInstance       An instance of a SplFileInfo class
-        * @return      $indexInstance  An instance of this Index class
-        */
-       public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
-               // Get a new instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
-               $indexInstance = new FileStackIndex();
-
-               // Initialize index
-               $indexInstance->initIndex($fileInfoInstance);
-
-               // Return the prepared instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: indexInstance=%s - EXIT!', $indexInstance->__toString()));
-               return $indexInstance;
-       }
-
-       /**
-        * Adds given data's hash to an index file
-        *
-        * @param       $groupId        Name of stack to add hash for
-        * @param       $data           Hash and gap position to be added to the index
-        * @return      void
-        * @throws      InvalidArgumentException        If a parameter is not valid
-        * @throws      UnexpectedValueException        If an invalid gap position is being returned
-        */
-       public function addHashedDataToIndex (string $groupId, array $data) {
-               // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,data()=%d - CALLED!', $groupId, count($data)));
-               if (empty($groupId)) {
-                       // Throw IAE
-                       throw new InvalidArgumentException('Parameter "groupId" is empty');
-               } elseif (count($data) == 0) {
-                       // Throw it again
-                       throw new InvalidArgumentException('Parameter "data" is an empty array');
-               } elseif (!isset($data[StackableFile::ARRAY_NAME_HASH])) {
-                       // Important array element missing
-                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_HASH]));
-               } elseif (!isset($data[StackableFile::ARRAY_NAME_GAP_POSITION])) {
-                       // Important array element missing
-                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_GAP_POSITION]));
-               } elseif (!isset($data[StackableFile::ARRAY_NAME_DATA_LENGTH])) {
-                       // Important array element missing
-                       throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_DATA_LENGTH]));
-               }
-
-               // Raw data been written to the file
-               $rawData = sprintf('%s%s%s%s%s%s%s',
-                       $groupId,
-                       Indexable::SEPARATOR_GROUP_HASH,
-                       hex2bin($data[StackableFile::ARRAY_NAME_HASH]),
-                       Indexable::SEPARATOR_HASH_GAP_POSITION,
-                       $data[StackableFile::ARRAY_NAME_GAP_POSITION],
-                       Indexable::SEPARATOR_GAP_LENGTH,
-                       $data[StackableFile::ARRAY_NAME_DATA_LENGTH]
-               );
-
-               // Search for next free gap
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d', $groupId, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
-               $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
-
-               // Gap position cannot be smaller or equal than header length
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gapPosition=%s', $groupId, $data[StackableFile::ARRAY_NAME_HASH], $gapPosition));
-               if ($gapPosition <= ($this->getIteratorInstance()->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)));
-               }
-
-               // Then write the data at that gap
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: Calling this->iteratorInstance->writeData(%d,%s) ...', $gapPosition, $rawData));
-               $this->getIteratorInstance()->writeData($gapPosition, $rawData);
-
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
-       }
-
-       /**
-        * Searches for next suitable gap the given length of data can fit in
-        * including padding bytes.
-        *
-        * @param       $length                 Length of raw data
-        * @return      $seekPosition   Found next gap's seek position
-        * @throws      InvalidArgumentException        If the parameter is not valid
-        * @todo        Unfinished work
-        */
-       public function searchNextGap (int $length) {
-               // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: length=%d - CALLED!', $length));
-               if ($length <= 0) {
-                       // Throw IAE
-                       throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
-               }
-
-               // Partial stub!
-               $this->partialStub('length=' . $length);
-       }
-
-       /**
-        * 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;
-       }
-
-       /**
-        * Checks if this index file has been fully and properly loaded.
-        *
-        * @return      $isLoaded       Whether this index file has been loaded
-        */
-       public function isIndexFileLoaded () {
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-STACK-INDEX: CALLED!');
-               /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
-       }
-
-}
index 0163ffed79afa326e269fa4a0fa3d4dc65575f1d..50a69ed9e322b2cb6e8441baf1fb67976c976009 100644 (file)
@@ -11,6 +11,7 @@ use Org\Mxchange\CoreFramework\Traits\File\BinaryFileTrait;
 // Import SPL stuff
 use \BadMethodCallException;
 use \InvalidArgumentException;
+use \OutOfBoundsException;
 
 /**
  * A file iterator
@@ -161,14 +162,14 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @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
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
        public function seek (int $seekPosition, int $whence = SEEK_SET) {
                // Validate parameter
                //* 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));
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
                }
 
                // Call file instance
@@ -199,13 +200,14 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         *
         * @param       $bytes  Amount of bytes to read
         * @return      $data   Data read from file
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
        public function read (int $bytes = 0) {
                // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: bytes=%d - CALLED!', $bytes));
                if ($bytes < 0) {
-                       // Throw IAE
-                       throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+                       // Throw exception
+                       throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
                }
 
                // Call file instance
@@ -411,16 +413,17 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @param       $data                   Data to be written
         * @param       $flushHeader    Whether to flush the header (default: flush)
         * @return      void
+        * @throws      OutOfBoundsException    If the position is not seekable
         * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
                // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,data(%d)=%s,flushHeader=%d - CALLED!', $seekPosition, strlen($data), $data, intval($flushHeader)));
                if ($seekPosition < 0) {
-                       // Throw IAE
-                       throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+                       // Throw exception
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
                } elseif (empty($data)) {
-                       // Throw it again
+                       // Throw IAE
                        throw new InvalidArgumentException('Parameter "data" is empty');
                }
 
@@ -438,6 +441,7 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         * @param       $seekPosition   Seek position in file
         * @param       $dataStream             Data to be written
         * @return      mixed                   Number of writes bytes or false on error
+        * @throws      OutOfBoundsException    If the position is not seekable
         * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function writeAtPosition (int $seekPosition, string $dataStream) {
@@ -445,7 +449,7 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
                //* 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));
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
                } elseif (empty($dataStream)) {
                        // Empty dataStream
                        throw new InvalidArgumentException('Parameter "dataStream" is empty');
@@ -478,24 +482,24 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
        /**
         * Writes given value to the file and returns a hash and gap position for it
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $value          Value to be added to the stack
         * @return      $data           Hash and gap position
         * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function writeValueToFile (string $groupId, $value) {
+       public function writeValueToFile (string $stackName, $value) {
                // Validate parameter
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,value[]=%s - CALLED!', $groupId, gettype($value)));
-               if (empty($groupId)) {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
+               if (empty($stackName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "groupId" is empty');
+                       throw new InvalidArgumentException('Parameter "stackName" is empty');
                } elseif (is_resource($value) || is_object($value)) {
                        // Resources and objects are nothing for file-based indexes (mostly)
                        throw new InvalidArgumentException(sprintf('value[]=%s is not supported by file-based indexes', gettype($value)));
                }
 
                // Call file instance
-               $data = $this->getBinaryFileInstance()->writeValueToFile($groupId, $value);
+               $data = $this->getBinaryFileInstance()->writeValueToFile($stackName, $value);
 
                // Return data
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
@@ -505,17 +509,17 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
        /**
         * Writes given raw data to the file and returns a gap position and length
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $hash           Hash from encoded value
         * @param       $encoded        Encoded value to be written to the file
         * @return      $data           Gap position and length of the raw data
         */
-       public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
+       public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
                // Validate parameter
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,hash=%s,encoded(%d)=%s - CALLED!', $groupId, $hash, strlen($encoded), $encoded));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,hash=%s,encoded(%d)=%s - CALLED!', $stackName, $hash, strlen($encoded), $encoded));
 
                // Call file instance
-               $data = $this->getBinaryFileInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
+               $data = $this->getBinaryFileInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
 
                // Return data
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
index 1b11c51adf1481352900ea1031cace08601c5bbf..aaaf94352d3d8ab825168586dac63cece0ec01c5 100644 (file)
@@ -99,37 +99,4 @@ class ConsoleOutput extends BaseOutput implements OutputStreamer {
                print trim($outStream) . PHP_EOL;
        }
 
-       /**
-        * Determines seek position
-        *
-        * @return      $seekPosition   Current seek position
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function determineSeekPosition () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Seek to given offset (default) or other possibilities as fseek() gives.
-        *
-        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
-        * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function seek (int $offset, int $whence = SEEK_SET) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Size of file stack
-        *
-        * @return      $size   Size (in bytes) of file
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function size () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
 }
index 3d7432279937c222eeec1aad027544a78e50b155..14bfb516f3c92b1b4ba174f66e7e6f30cfa5c10f 100644 (file)
@@ -50,7 +50,7 @@ abstract class BaseDebugOutput extends BaseOutput {
         * @param       $loggerClassName        Class name this output class is being used for logging
         * @return      void
         */
-       public final function setLoggerClassName ($loggerClassName) {
+       public final function setLoggerClassName (string $loggerClassName) {
                $this->loggerClassName = $loggerClassName;
        }
 
index 8f7d19f6641b007d10752717bd6cf1b5f4f26ad1..a43b7674280c0f7539cdf8c9f00fe65afe777748 100644 (file)
@@ -106,37 +106,4 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
-       /**
-        * Determines seek position
-        *
-        * @return      $seekPosition   Current seek position
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function determineSeekPosition () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Seek to given offset (default) or other possibilities as fseek() gives.
-        *
-        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
-        * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function seek (int $offset, int $whence = SEEK_SET) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Size of file stack
-        *
-        * @return      $size   Size (in bytes) of file
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function size () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
 }
index 7903b910acbe96cda921f9c4ce1bf97bd39c6540..5690466e1eab7e648729466a1d731e328ce24cf2 100644 (file)
@@ -104,37 +104,4 @@ class DebugErrorLogOutput extends BaseDebugOutput implements Debugger, OutputStr
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
-       /**
-        * Determines for seek position
-        *
-        * @return      $seekPosition   Current seek position
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function determineSeekPosition () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Seek to given offset (default) or other possibilities as fseek() gives.
-        *
-        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
-        * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function seek (int $offset, int $whence = SEEK_SET) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-ERROR-LOG-OUTPUT: offset=' . $offset . ',whence=' . $whence);
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Size of file stack
-        *
-        * @return      $size   Size (in bytes) of file
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function size () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
 }
index e2656b1da4b3d1a3cc763ed74b3b90a6f94ef04d..598f06d6280f24afc93fc91561944c1ccab5b75a 100644 (file)
@@ -93,37 +93,4 @@ class DebugWebOutput extends BaseDebugOutput implements Debugger, OutputStreamer
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
-       /**
-        * Determines seek position
-        *
-        * @return      $seekPosition   Current seek position
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function determineSeekPosition () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Seek to given offset (default) or other possibilities as fseek() gives.
-        *
-        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
-        * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function seek (int $offset, int $whence = SEEK_SET) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Size of file stack
-        *
-        * @return      $size   Size (in bytes) of file
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function size () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
 }
index 6abfc10fc1068765637473678c300da81ae5eb5f..01d14239b94831944f753fd0e278f829668d9a32 100644 (file)
@@ -5,7 +5,6 @@ namespace Org\Mxchange\CoreFramework\Output;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
-use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
 use Org\Mxchange\CoreFramework\Output\BaseOutput;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
@@ -52,10 +51,9 @@ class WebOutput extends BaseOutput implements OutputStreamer, Registerable {
        /**
         * Create a new web output system and set the content type
         *
-        * @param       $applicationInstance    An instance of a ManageableApplication class
-        * @return      $debugInstance                  An instance of this middleware class
+        * @return      $webInstance    An instance of an OutputStreamer class
         */
-       public static final function createWebOutput (ManageableApplication $applicationInstance) {
+       public static final function createWebOutput () {
                // Is the self-instance already set?
                if (is_null(self::$webInstance)) {
                        // Get a new instance and set it
@@ -68,8 +66,8 @@ class WebOutput extends BaseOutput implements OutputStreamer, Registerable {
                        if (!empty($contentType)) {
                                // Set the header
                                FrameworkBootstrap::getResponseInstance()->addHeader('Content-type', $contentType);
-                       } // END - if
-               } // END - if
+                       }
+               }
 
                // Return instance
                return self::$webInstance;
@@ -86,37 +84,4 @@ class WebOutput extends BaseOutput implements OutputStreamer, Registerable {
                print(stripslashes($outStream));
        }
 
-       /**
-        * Determines seek position
-        *
-        * @return      $seekPosition   Current seek position
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function determineSeekPosition () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Seek to given offset (default) or other possibilities as fseek() gives.
-        *
-        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
-        * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function seek (int $offset, int $whence = SEEK_SET) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Size of file stack
-        *
-        * @return      $size   Size (in bytes) of file
-        * @throws      UnsupportedOperationException   If this method is called
-        */
-       public function size () {
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
 }
index 66345fd72112ad7f76bbc920d0912a4268df91af..6b4a8bfb0f58982df285a06ca2251ea08c089a96 100644 (file)
@@ -72,7 +72,7 @@ abstract class BaseFileStack extends BaseStacker {
         * @throws      UnexpectedValueException        If header is not proper length
         * @throws      InvalidMagicException   If a bad magic was found
         */
-       public function readFileHeader () {
+       public function readStackHeader () {
                // First rewind to beginning as the header sits at the beginning ...
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
                $this->getIteratorInstance()->rewind();
@@ -254,8 +254,8 @@ abstract class BaseFileStack extends BaseStacker {
                }
 
                // Load the file header
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->readFileHeader() ...');
-               $this->readFileHeader();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->readStackHeader() ...');
+               $this->readStackHeader();
 
                /*
                 * Get stack index instance. This can be used for faster
@@ -269,8 +269,8 @@ abstract class BaseFileStack extends BaseStacker {
                $this->setIndexInstance($indexInstance);
 
                // Is the index loaded correctly and the stack file is just created?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->indexInstance->isIndexFileLoaded() ...');
-               if (!$this->getIndexInstance()->isIndexFileLoaded()) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->indexInstance->isIndexLoaded() ...');
+               if (!$this->getIndexInstance()->isIndexLoaded()) {
                        /*
                         * Something horrible has happened to the index as it should be
                         * loaded at this point. The stack's file structure then needs to
@@ -649,13 +649,13 @@ abstract class BaseFileStack extends BaseStacker {
        /**
         * Writes given value to the file and returns a hash and gap position for it
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $value          Value to be added to the stack
         * @return      $data           Hash and gap position
         * @throws      UnsupportedOperationException   This method is not (and maybe never will be) supported
         */
-       public function writeValueToFile (string $groupId, $value) {
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,value[%s]=%s', $groupId, gettype($value), print_r($value, true)));
+       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);
        }
 
@@ -691,16 +691,16 @@ abstract class BaseFileStack extends BaseStacker {
        /**
         * Writes given raw data to the file and returns a gap position and length
         *
-        * @param       $groupId        Group identifier
+        * @param       $stackName      Group identifier
         * @param       $hash           Hash from encoded value
         * @param       $encoded        Encoded value to be written to the file
         * @return      $data           Gap position and length of the raw data
         */
-       public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
+       public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
                // Raw data been written to the file
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,encoded()=%d - CALLED!', $groupId, $hash, strlen($encoded)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,encoded()=%d - CALLED!', $stackName, $hash, strlen($encoded)));
                $rawData = sprintf('%s%s%s%s%s',
-                       $groupId,
+                       $stackName,
                        BaseBinaryFile::SEPARATOR_GROUP_HASH,
                        hex2bin($hash),
                        BaseBinaryFile::SEPARATOR_HASH_VALUE,
@@ -708,7 +708,7 @@ abstract class BaseFileStack extends BaseStacker {
                );
 
                // Search for next free gap
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,rawData()=%d', $groupId, $hash, strlen($rawData)));
+               /* 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));
 
                // Gap position cannot be smaller than header length + 1
@@ -723,11 +723,11 @@ abstract class BaseFileStack extends BaseStacker {
                }
 
                // Then write the data at that gap
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,gapPosition=%s', $groupId, $hash, $gapPosition));
+               /* 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);
 
                // Return gap position, hash and length of raw data
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $hash, strlen($rawData)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,rawData()=%d - EXIT!', $stackName, $hash, strlen($rawData)));
                return [
                        self::ARRAY_NAME_GAP_POSITION => $gapPosition,
                        self::ARRAY_NAME_HASH         => $hash,
index 42eab523b6cab53796820dad5f15eb6a0ffcba60..16a5f263d783ae5502b99b0eebb0c10a1e12cb8e 100644 (file)
@@ -10,6 +10,7 @@ use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
 
 // Import SPL stuff
 use \InvalidArgumentException;
+use \OutOfBoundsException;
 use \SplFileInfo;
 
 /**
@@ -162,14 +163,14 @@ class FiFoFileStack extends BaseFileStack implements StackableFile, Calculatable
         * @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
+        * @throws      OutOfBoundsException    If the position is not seekable
         */
        public function seek (int $seekPosition, int $whence = SEEK_SET) {
                // Validate parameter
                /* 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));
+                       throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
                }
 
                // @TODO Unfinished method or invoke inner iterator's method?
index d09095a21945a99ff72a32d04dd035ab3464244d..5eba1b56def88eaab6297c1b3a6ca3fde8d663bf 100644 (file)
@@ -48,4 +48,11 @@ interface Indexable extends FrameworkInterface {
         */
        const SEPARATOR_GAP_LENGTH = 0x03;
 
+       /**
+        * Checks whether the index has been fully loaded (and parsed)
+        *
+        * @return      $isLoaded       Whether the index has been loaded
+        */
+       function isIndexLoaded ();
+
 }
diff --git a/framework/main/interfaces/index/file/class_FileIndexer.php b/framework/main/interfaces/index/file/class_FileIndexer.php
new file mode 100644 (file)
index 0000000..9a90b36
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Index\Indexable;
+
+/**
+ * An interface for indexable file classes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface FileIndexer extends Indexable {
+       /**
+        * Adds given data's hash to the index file
+        *
+        * @param       $stackName      Name of stack to add hash
+        * @param       $data           Hash and gap position to be added to the index
+        * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        */
+       function addHashedDataToIndex (string $stackName, array $data);
+
+       /**
+        * Searches for next suitable gap the given length of data can fit in
+        * including padding bytes.
+        *
+        * @param       $length                 Length of raw data
+        * @return      $seekPosition   Found next gap's seek position
+        * @throws      InvalidArgumentException        If the parameter is not valid
+        */
+       function searchNextGap (int $length);
+
+       /**
+        * 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);
+
+}
diff --git a/framework/main/interfaces/index/file/stack/class_IndexableStack.php b/framework/main/interfaces/index/file/stack/class_IndexableStack.php
new file mode 100644 (file)
index 0000000..be0a44c
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File\Stack;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
+use Org\Mxchange\CoreFramework\Index\File\FileIndexer;
+
+/**
+ * An interface for Indexable stack classes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface IndexableStack extends FileIndexer {
+
+}
diff --git a/framework/main/interfaces/index/stack/class_IndexableStack.php b/framework/main/interfaces/index/stack/class_IndexableStack.php
deleted file mode 100644 (file)
index 2576ce5..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Index\Stack;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
-use Org\Mxchange\CoreFramework\Index\Indexable;
-
-/**
- * An interface for Indexable stack classes
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface IndexableStack extends Indexable, CalculatableBlock {
-       /**
-        * Adds given data's hash to the index file
-        *
-        * @param       $stackName      Name of stack to add hash
-        * @param       $data           Hash and gap position to be added to the index
-        * @return      void
-        * @throws      InvalidArgumentException        If a parameter is not valid
-        */
-       function addHashedDataToIndex (string $stackName, array $data);
-
-       /**
-        * Checks whether the index' file has been fully loaded (and parsed)
-        *
-        * @return      $isLoaded       Whether the index' file has been loaded
-        */
-       function isIndexFileLoaded ();
-
-}
index 3fe663d31be0e154ccd3b3d7f88b82232cbd02eb..a9dede2e1dc1bc8cba5e8375b92564d1df69eaa5 100644 (file)
@@ -28,27 +28,5 @@ use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface Streamable extends FrameworkInterface {
-       /**
-        * Determines seek position
-        *
-        * @return      $seekPosition   Current seek position
-        */
-       function determineSeekPosition ();
-
-       /**
-        * Seek to given offset (default) or other possibilities as fseek() gives.
-        *
-        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
-        * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
-        */
-       function seek (int $offset, int $whence = SEEK_SET);
-
-       /**
-        * Size of file stack
-        *
-        * @return      $size   Size (in bytes) of file
-        */
-       function size ();
 
 }
index 49e4a9d929d58841cf83c9ed2e5213c4927c05ab..400509ab07d8e7c08a31ea769d6d104c576293fb 100644 (file)
@@ -28,5 +28,28 @@ use Org\Mxchange\CoreFramework\Stream\Streamable;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface StreamableInput extends Streamable {
+       /**
+        * Determines seek position
+        *
+        * @return      $seekPosition   Current seek position
+        */
+       function determineSeekPosition ();
+
+       /**
+        * Seek to given offset (default) or other possibilities as fseek() gives.
+        *
+        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
+        * @param       $whence         Added to offset (default: only use offset to seek to)
+        * @return      void
+        * @throws      OutOfBoundsException    If the position is not seekable
+        */
+       function seek (int $offset, int $whence = SEEK_SET);
+
+       /**
+        * Size of file stack
+        *
+        * @return      $size   Size (in bytes) of file
+        */
+       function size ();
 
 }
index 21ad59ef416c4b046d9fa17772b4537b14860cf4..64e49f53176d10750ad1fb89313bb561b205f903 100644 (file)
@@ -29,14 +29,6 @@ use \SeekableIterator;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface SeekableWritableFileIterator extends SeekableIterator {
-       /**
-        * Seeks to given position
-        *
-        * @param       $seekPosition   Seek position in file
-        * @return      $status                 Status of this operation
-        */
-       function seek (int $seekPosition);
-
        /**
         * Size of file stack
         *
index f01e8b3d39c57521828d2ebce7e0a9b066798e0f..2d8094b1e5037f2cc30b489ec1a70901e02d6dc7 100644 (file)
@@ -64,14 +64,14 @@ interface StackableFile extends Stackable {
        function size ();
 
        /**
-        * Reads the file header
+        * Reads the stack's file header
         *
         * @return      void
         * @todo        To hard assertions here, better rewrite them to exceptions
         * @throws      UnexpectedValueException        If header is not proper length
         * @throws      InvalidMagicException   If a bad magic was found
         */
-       function readFileHeader ();
+       function readStackHeader ();
 
        /**
         * Flushes the file header
index dfdcd79e527249b6cfbc8f0b109a076db9089fe3..2b0aa9bc65f3beed2da5985de035bd4962f7ea8f 100644 (file)
@@ -154,7 +154,7 @@ class FileIoHandler extends BaseMiddleware implements IoHandler {
         *
         * @param       $offset         Offset to seek to (or used as "base" for other seeks)
         * @param       $whence         Added to offset (default: only use offset to seek to)
-        * @return      $status         Status of file seek: 0 = success, -1 = failed
+        * @return      void
         */
        public function seek (int $offset, int $whence = SEEK_SET) {
                $this->partialStub('offset=' . $offset . ',whence=' . $whence);
diff --git a/framework/main/traits/index/stack/class_IndexableStackTrait.php b/framework/main/traits/index/stack/class_IndexableStackTrait.php
deleted file mode 100644 (file)
index 15e46ac..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Traits\Index\Stack;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
-
-/**
- * A trait for indexable stacks
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-trait IndexableStackTrait {
-       /**
-        * An instance of an IndexableStack class
-        */
-       private $indexInstance = NULL;
-
-       /**
-        * Setter for IndexableStack instance
-        *
-        * @param       $indexInstance  An instance of an IndexableStack class
-        * @return      void
-        */
-       protected final function setIndexableStackInstance (IndexableStack $indexInstance) {
-               $this->indexInstance = $indexInstance;
-       }
-
-       /**
-        * Getter for IndexableStack instance
-        *
-        * @return      $indexInstance  An instance of an IndexableStack class
-        */
-       public final function getIndexableStackInstance () {
-               return $this->indexInstance;
-       }
-
-}