]> git.mxchange.org Git - core.git/commitdiff
WIP:
authorRoland Häder <roland@mxchange.org>
Wed, 6 Jan 2021 19:28:35 +0000 (20:28 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 6 Jan 2021 19:28:35 +0000 (20:28 +0100)
- thrown exceptions when parameter values/types are not valid
- added type-hints for primitive variables
- partially fixed writing index files for other non-humanreadable files (see
  BaseBinaryFile class)

Signed-off-by: Roland Häder <roland@mxchange.org>
13 files changed:
framework/main/classes/criteria/search/class_SearchCriteria.php
framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.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/index/class_BaseIndex.php
framework/main/classes/index/file/class_BaseFileIndex.php
framework/main/classes/iterator/file/class_FileIterator.php
framework/main/classes/stacker/file/class_BaseFileStack.php
framework/main/interfaces/criteria/search/class_LocalSearchCriteria.php
framework/main/interfaces/filesystem/binary/class_BinaryFile.php
framework/main/interfaces/iterator/file/class_SeekableWritableFileIterator.php
framework/main/middleware/compressor/class_CompressorChannel.php

index 7aca53907e3318e987c20cf10161912e19154352..b9286d0e88162ce426e6bb32001f440825799165 100644 (file)
@@ -7,6 +7,9 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Criteria\BaseCriteria;
 use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * Search criteria for e.g. searching in databases. Do not use this class if
  * you are looking for a ship or company, or what ever. Instead use this class
@@ -77,7 +80,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
         * @return      void
         * @todo        Find a nice casting here. (int) allows until and including 32766.
         */
-       public final function setLimit ($limit) {
+       public final function setLimit (int $limit) {
                $this->limit = $limit;
        }
 
@@ -87,7 +90,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
         * @param       $configEntry    The configuration entry which hold a number as limit
         * @return      void
         */
-       public final function setConfiguredLimit ($configEntry) {
+       public final function setConfiguredLimit (string $configEntry) {
                // Get the limit from config entry and set it
                $limit = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry);
                $this->setLimit($limit);
@@ -109,7 +112,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
         * @return      void
         * @todo        Find a nice casting here. (int) allows until and including 32766.
         */
-       public final function setSkip ($skip) {
+       public final function setSkip (int $skip) {
                $this->skip = $skip;
        }
 
@@ -130,39 +133,53 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
         * @param       $value                  Value to check
         * @param       $separator              Separator for "exploding" $value (default: ',')
         * @return      $isMatching             Whether the key/value is matching or excluded
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
-       public function isCriteriaMatching ($key, $value, $separator = ',') {
+       public function isCriteriaMatching (string $key, $value, string $separator = ',') {
                // $key/$value cannot be array/NULL/bool, value can be NULL but then NULL must be loocked for
-               assert((!is_array($value)) && (!is_bool($value)) && (!is_array($key)) && (!is_null($key)) && (!is_bool($key)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SEARCH-CRITERIA: key=%s,value[]=%s,separator=%s - CALLED!', $key, gettype($value), $separator));
+               if (empty($key)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "key" cannot be empty');
+               } elseif (is_array($value) || is_bool($value) || is_bool($value) || is_object($value) || is_resource($value)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('value[]=%s is not supported/valid', gettype($value)));
+               } elseif (empty($separator)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "separator" cannot be empty');
+               }
 
                // "Explode" value
                $valueArray = explode($separator, $value);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: key=' . $key . ',value[' . gettype($value) . ']=' . $value . ' - CALLED!');
-
                // Get 'default' search value
                $searchDefault = $this->getCriteriaElemnent($key);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault);
-
                // 'default' check
-               $isMatching = (((($searchDefault !== false) && ($searchDefault == $value)) || ((is_null($searchDefault)) && (is_null($value)))) || ($searchDefault === false));
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault . ',isMatching=' . intval($isMatching));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault);
+               $isMatching = (
+                       (
+                               (
+                                       ($searchDefault !== false) &&
+                                       ($searchDefault == $value)
+                               ) || (
+                                       is_null($searchDefault) &&
+                                       is_null($value)
+                               )
+                       ) || (
+                               $searchDefault === false
+                       )
+               );
 
                // Get 'choice' search value (can be NULL or $separator-separated string)
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault . ',isMatching=' . intval($isMatching));
                $searchChoice = $this->getCriteriaChoiceElemnent($key);
 
                // May be false or array
                assert(($searchChoice === false) || (is_array($searchChoice)));
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaChoiceElement(' . $key . ')[' . gettype($searchChoice) . ']=' . print_r($searchChoice, true));
-
                // 'choice' check
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaChoiceElement(' . $key . ')[' . gettype($searchChoice) . ']=' . print_r($searchChoice, true));
                if ((is_array($searchChoice)) && (count($valueArray) == 1)) {
                        // $value is a single-search value, so use in_[]
                        $isMatching = ((($isMatching === true) || (($searchDefault === false) && (!is_null($value)))) && (in_array($value, $searchChoice)));
@@ -195,16 +212,12 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - false-MATCH');
                }
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',isMatching=' . intval($isMatching));
-
                // Get 'exclude' search value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',isMatching=' . intval($isMatching));
                $searchExclude = $this->getCriteriaExcludeElemnent($key);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaExcludeElement(' . $key . ')[' . gettype($searchExclude) . ']=' . $searchExclude);
-
                // 'exclude' check
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SEARCH-CRITERIA: getCriteriaExcludeElement(' . $key . ')[' . gettype($searchExclude) . ']=' . $searchExclude);
                $isMatching = (
                        (
                                (
index b2d9041e256553ff8af60a71d4cf4cea11f6b50f..3c021c7deaa75ef0409b63e951a4221682f856df 100644 (file)
@@ -391,7 +391,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                        $idx = 1;
 
                        // Read the directory with some exceptions
-                       while (($fileInfoInstance = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
+                       while (($fileInfoInstance = $directoryInstance->readDirectoryExcept(['.gitkeep', 'info.' . $this->getFileExtension()])) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
                                // Does the extension match?
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: fileInfoInstance->extension=%s,this->fileExtension=%s', $fileInfoInstance->getExtension(), $this->getFileExtension()));
                                if ($fileInfoInstance->getExtension() !== $this->getFileExtension()) {
@@ -413,9 +413,6 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                                        // Search in the criteria with FMFW (First Matches, First Wins)
                                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: data[]=%d', count($dataArray)));
                                        foreach ($dataArray as $key => $value) {
-                                               // Make sure value is not bool
-                                               assert(!is_bool($value));
-
                                                // Found one entry?
                                                $isFound = (($isFound === true) && ($searchInstance->isCriteriaMatching($key, $value)));
                                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: key=%s,value[%s]=%s,isFound=%s', $key, gettype($value), $value, intval($isFound)));
@@ -547,7 +544,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                        $searchInstance = $dataSetInstance->getSearchInstance();
 
                        // Read the directory with some exceptions
-                       while (($fileInfoInstance = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
+                       while (($fileInfoInstance = $directoryInstance->readDirectoryExcept(['.gitkeep', 'info.' . $this->getFileExtension()])) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
                                // Does the extension match?
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance->extension=' . $fileInfoInstance->getExtension() . ',this->getFileExtension()=' . $this->getFileExtension());
                                if ($fileInfoInstance->getExtension() !== $this->getFileExtension()) {
@@ -568,9 +565,6 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
 
                                        // Search in the criteria with FMFW (First Matches, First Wins)
                                        foreach ($dataArray as $key => $value) {
-                                               // Make sure value is not bool
-                                               assert(!is_bool($value));
-
                                                // Found one entry?
                                                $isFound = (($isFound === true) && ($searchInstance->isCriteriaMatching($key, $value)));
                                        }
@@ -704,7 +698,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                        $count = 0;
 
                        // Read the directory with some exceptions
-                       while ($fileInfoInstance = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) {
+                       while ($fileInfoInstance = $directoryInstance->readDirectoryExcept(['.gitkeep', 'info.' . $this->getFileExtension()])) {
                                // Does the extension match?
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance->extension=' . $fileInfoInstance->getExtension() . ',this->getFileExtension()=' . $this->getFileExtension());
                                if ($fileInfoInstance->getExtension() !== $this->getFileExtension()) {
index 95c642eb066f72b4330566218d486794b351fdea..2bfc27716044ad3d6b06233ee850cbe36439c17d 100644 (file)
@@ -7,6 +7,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
 use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
+use Org\Mxchange\CoreFramework\Filesystem\FilePointer;
 use Org\Mxchange\CoreFramework\Index\Indexable;
 use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
 use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
@@ -153,9 +154,6 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
        protected function __construct (string $className) {
                // Call parent constructor
                parent::__construct($className);
-
-               // Init counters and gaps array
-               $this->initCountersGapsArray();
        }
 
        /**
@@ -263,36 +261,18 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                $this->seekPosition = $seekPosition;
        }
 
-       /**
-        * Marks whole file as gaps-only (freshly created file
-        *
-        * @param       $type   Type of file
-        * @param       $minimumBlockLength             Minimum block length
-        * @return      void
-        */
-       private function markFileGapsOnly (string $type, int $minimumBlockLength) {
-               // Very simple to do ...
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength));
-               for ($idx = 0; $idx < FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count'); $idx++) {
-                       // Mark start and end position as gap
-                       $this->addGap($idx * $minimumBlockLength, $idx * $minimumBlockLength + $minimumBlockLength);
-               }
-
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
-       }
-
        /**
         * Checks whether the abstracted file only contains gaps by counting all
         * gaps' bytes together and compare it to total length.
         *
         * @return      $isGapsOnly             Whether the abstracted file only contains gaps
+        * @throws      OutOfBoundsException    If calculated file size is larger than actual
         */
-       private function isFileGapsOnly () {
+       public function isFileGapsOnly () {
                // Count every gap
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                $gapsSize = 0;
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->gaps()=%d', count($this->gaps)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->gaps()=%d', count($this->gaps)));
                foreach ($this->gaps as $gap) {
                        // Calculate size of found gap: end-start including both
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gap[%s]=%d,ga[%s]=%d', self::GAPS_INDEX_START, $gap[self::GAPS_INDEX_START], self::GAPS_INDEX_END, $gap[self::GAPS_INDEX_END]));
@@ -302,15 +282,49 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gapsSize=%d', $gapsSize));
                }
 
-               // Total gap size + header size must be same as file size
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gapsSize=%d,this->fileSize=%d', $gapsSize, $this->getFileSize()));
-               $isGapsOnly = ($gapsSize + 1 == $this->getFileSize());
+               // Total gap size + header size + 1 must be same as file size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: gapsSize=%d,this->headerSize=%d,this->fileSize=%d', $gapsSize, $this->getHeaderSize(), $this->getFileSize()));
+               $determinedFileSize = ($gapsSize + $this->getHeaderSize() + 1);
 
-               // Return status
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isGapsOnly=%d - EXIT!', intval($isGapsOnly)));
+               // Should not be more!
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: determinedFileSize=%d,this->fileSize=%d', $determinedFileSize, $this->getFileSize()));
+               if ($determinedFileSize > $this->getFileSize()) {
+                       // Should not happen
+                       throw new OutOfBoundsException(sprintf('determinedFileSize=%d is larger than this->fileSize=%d', $determinedFileSize, $this->getFileSize()));
+               }
+
+               // Is it same?
+               $isGapsOnly = ($determinedFileSize == $this->getFileSize());
+
+               // Return flag
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isGapsOnly=%d - EXIT!', intval($isGapsOnly)));
                return $isGapsOnly;
        }
 
+       /**
+        * Marks whole file as gaps-only (freshly created file
+        *
+        * @param       $type   Type of file
+        * @param       $minimumBlockLength             Minimum block length
+        * @return      void
+        */
+       private function markFileGapsOnly (string $type, int $minimumBlockLength) {
+               // Very simple to do ...
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength));
+               for ($idx = 0; $idx < FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count'); $idx++) {
+                       // Calculate start/end positions
+                       $startPosition = $idx * $minimumBlockLength;
+                       $endPosition = $idx * $minimumBlockLength + $minimumBlockLength;
+
+                       // Mark start and end position as gap
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ...', $startPosition, $endPosition));
+                       $this->addGap($startPosition, $endPosition);
+               }
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+       }
+
        /**
         * Adds a gap for given start and end position
         *
@@ -423,7 +437,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                $currentPosition = $this->determineSeekPosition();
 
                // Now add it as gap entry
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: currentPosition=%d', $currentPosition));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ..', ($currentPosition - $length), $currentPosition));
                $this->addGap(($currentPosition - $length), $currentPosition);
 
                // Trace message
@@ -440,14 +454,28 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         */
        public function initCountersGapsArray () {
                // Init counter and seek position to header size
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->determineSeekPosition() - CALLED!');
+               $seekPosition = $this->getSeekPosition();
+
+               // Set counter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
                $this->setCounter(0);
-               $this->setSeekPosition($this->getHeaderSize());
+
+               // Get header size
+               $headerSize = $this->getHeaderSize();
+
+               // Set it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting this->seekPosition=%d ...', $headerSize));
+               $this->setSeekPosition($headerSize);
 
                // Init arrays
                $this->gaps = [];
                $this->damagedEntries = [];
 
+               // Seek back to old position
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->seek(%d) ...', $seekPosition));
+               $this->seek($seekPosition);
+
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
@@ -505,7 +533,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         */
        public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
                // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader)));
+               //* 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 OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
@@ -515,31 +543,31 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                }
 
                // Write data at given position
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,%s) ...', $seekPosition, $data));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,%s) ...', $seekPosition, $data));
                $this->writeAtPosition($seekPosition, $data);
 
                // Increment counter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->incrementCounter() ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->incrementCounter() ...');
                $this->incrementCounter();
 
                // Update seek position
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...');
                $this->updateSeekPosition();
 
                // Flush the header?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: flushHeader=%d', intval($flushHeader)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: flushHeader=%d', intval($flushHeader)));
                if ($flushHeader === true) {
                        // Flush header
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->flushFileHeader() ...');
                        $this->flushFileHeader();
 
                        // Seek to old position
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->seekToOldPosition() ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->seekToOldPosition() ...');
                        $this->seekToOldPosition();
                }
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
@@ -659,60 +687,6 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
-       /**
-        * Pre-allocates file (if enabled) with some space for later faster write access.
-        *
-        * @param       $type   Type of the file
-        * @return      void
-        * @throws      InvalidArgumentException        If a parameter is empty
-        */
-       public function preAllocateFile (string $type) {
-               // Is it enabled?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s - CALLED!', $type));
-               if (empty($type)) {
-                       // Empty type
-                       throw new InvalidArgumentException('Parameter "type" is empty');
-               } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
-                       // Don't continue here.
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Not pre-allocating file.'));
-                       return;
-               }
-
-               // Message to user
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
-
-               // Calculate minimum length for one entry and get file size
-               $minimumBlockLength = $this->getIndexInstance()->calculateMinimumBlockLength();
-               $fileSize = $this->getFileSize();
-
-               // Calulcate seek position
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minimumBlockLength=%d,fileSize=%d', $minimumBlockLength, $fileSize));
-               $seekPosition = $minimumBlockLength * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count') + $fileSize ;
-
-               // Now simply write a NUL there. This will pre-allocate the file.
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,NUL) ...', $seekPosition));
-               $this->writeAtPosition($seekPosition, chr(0));
-
-               // Is the seek position zero?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize=%d', $fileSize));
-               if ($fileSize == 0) {
-                       // Mark file as gaps-only
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->markGapsOnly(%s,%d) ...', $type, $minimumBlockLength));
-                       $this->markFileGapsOnly($type, $minimumBlockLength);
-               } else {
-                       // Analyze file structure
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->analyzeFileStructure() ...');
-                       $this->analyzeFileStructure();
-               }
-
-               // Rewind seek position
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...');
-               $this->rewind();
-
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
-       }
-
        /**
         * Determines seek position
         *
@@ -768,8 +742,13 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                }
 
                // Call pointer instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->pointerInstance->read(%d) ...', $bytes));
                $data = $this->getPointerInstance()->read($bytes);
 
+               // Update seek position
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->updateSeekPosition() ...');
+               $this->updateSeekPosition();
+
                // Return data
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data[%s]=%s - EXIT!', gettype($data), $data));
                return $data;
@@ -799,25 +778,25 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
         */
        public function analyzeFileStructure () {
                // Make sure the file is initialized
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
                if (!$this->isFileInitialized()) {
                        // Bad method call
                        throw new BadMethodCallException('Method called but file is not initialized.');
                }
 
                // Init counters and gaps array
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->initCounterGapsArrays() ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->initCounterGapsArrays() ...');
                $this->initCountersGapsArray();
 
                // Output message (as this may take some time)
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Analyzing file structure ... (this may take some time)'));
 
                // First rewind to the begining
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...');
                $this->rewind();
 
                // Then try to load all entries
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Looping through file');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Looping through file');
                while ($this->isValid()) {
                        // Get current entry
                        $current = $this->getCurrentBlock();
@@ -831,68 +810,62 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                         * that the file has been pre-allocated.
                         */
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current(%d)[]=%s', strlen($current), gettype($current)));
-                       if (empty($current)) {
+                       if (empty(trim($current, chr(0)))) {
                                // Then skip this part
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current[]=%s is empty - CONTINUE!', gettype($current)));
                                continue;
                        }
 
                        // Handle current record
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current(%d)[]=%s', strlen($current), gettype($current)));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current(%d)[%s]=%s', strlen($current), gettype($current), $current));
                }
 
                // If the last read block is empty, check gaps
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current()=%d', strlen($current)));
-               if (empty($current)) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current()=%d', strlen($current)));
+               if (empty(trim($current, chr(0)))) {
                        // Output message
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Found a total of %d gaps.', count($this->gaps)));
 
                        // Check gaps, if the whole file is empty.
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->isFileGapsOnly() ...');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->isFileGapsOnly() ...');
                        if ($this->isFileGapsOnly()) {
                                // Only gaps, so don't continue here.
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: File is gaps-only - EXIT!');
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: File is gaps-only - EXIT!');
                                return;
                        }
+               }
 
-                       /*
-                        * The above call has calculated a total size of all gaps. If the
-                        * percentage of gaps passes a "soft" limit and last
-                        * defragmentation is to far in the past, or if a "hard" limit has
-                        * reached, run defragmentation.
-                        */
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->isDefragmentationNeeded() ...');
-                       if ($this->isDefragmentationNeeded()) {
-                               // Run "defragmentation"
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->doRunDefragmentation() ...');
-                               $this->doRunDefragmentation();
-                       }
+               /*
+                * The above call has calculated a total size of all gaps. If the
+                * percentage of gaps passes a "soft" limit and last
+                * defragmentation is to far in the past, or if a "hard" limit has
+                * reached, run defragmentation.
+                */
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->isDefragmentationNeeded() ...');
+               if ($this->isDefragmentationNeeded()) {
+                       // Run "defragmentation"
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->doRunDefragmentation() ...');
+                       $this->doRunDefragmentation();
                }
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
        /**
-        * Reads next "block" of bytes into $currentBlock field
+        * Reads next "block" of bytes into $currentBlock field. THis method loads
+        * the whole file into memory when the file is just freshly initialized
+        * (only zeros in it).
         *
         * @return      void
-        * @throws      BadMethodCallException  If this method was called without prior valid() call
         */
-       public function readNextBlock () {
-               // Is there nothing to read?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               if (!$this->isValid()) {
-                       // Nothing to read
-                       throw new BadMethodCallException('next() invoked but no valid current block (EOF?)');
-               }
-
+       private function readNextBlock () {
                // First calculate minimum block length
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d', $this->determineSeekPosition()));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d - CALLED!', $this->getSeekPosition()));
                $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().
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,length=%d', $this->getSeekPosition(), $length));
                $data = $this->getBackBuffer();
 
                /*
@@ -900,42 +873,40 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                 * "block" may not fit, so this loop will continue until the EOB or EOF
                 * has been reached whatever comes first.
                 */
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data()=%d', strlen($data)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,data()=%d', $this->getSeekPosition(), strlen($data)));
                while ((!$this->isEndOfFileReached()) && (empty($data) || !self::isBlockSeparatorFound($data))) {
                        // Then read the next possible block
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->read(%d) ...', $length));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, calling this->read(%d) ...', $this->getSeekPosition(), $length));
                        $block = $this->read($length);
 
-                       // Is it all empty?
+                       // Is the block empty?
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: block()=%d,length=%d', strlen($block), $length));
-                       if (strlen(trim($block, chr(0))) == 0) {
-                               // Mark this block as empty
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->markCurrentBlockAsEmpty(%d) ...', strlen($block)));
-                               $this->markCurrentBlockAsEmpty(strlen($block));
-
-                               // Exit look
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Empty block found ... - BREAK!');
-                               break;
+                       if (empty(trim($block, chr(0)))) {
+                               // Mark it as empty
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, calling this->markCurrentBlockAsEmpty(%d) ...', $this->getSeekPosition(), $length));
+                               $this->markCurrentBlockAsEmpty($length);
                        }
 
                        // At this block then
                        $data .= $block;
 
-                       // A debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data(%d)=%s', strlen($data), $data));
+                       // Debug message
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d,data()=%d', $this->getSeekPosition(), strlen($data)));
                }
 
                /*
                 * Init back-buffer which is the data that has been found beyond the
                 * separator.
                 */
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->initBackBuffer(), clearing this->currentBlock ...');
                $this->initBackBuffer();
+               $this->setCurrentBlock('');
 
                // Is $data empty?
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data(%d)=%s', strlen($data), $data));
-               if (empty($data)) {
+               if (empty(trim($data, chr(0)))) {
                        // Yes, maybe whole file was ...
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Maybe empty file found - EXIT!');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, maybe empty file found - EXIT!', $this->getSeekPosition()));
                        return;
                }
 
@@ -948,8 +919,9 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                $this->setCurrentBlock($dataArray[0]);
 
                // Is back buffere data found?
-               if (isset($dataArray[1])) {
+               if (!empty(trim($dataArray[1], chr(0)))) {
                        // Set back buffer
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting this->backBuffer=%s ...', $dataArray[1]));
                        $this->setBackBuffer($dataArray[1]);
                }
 
@@ -957,42 +929,92 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
+       /**
+        * Pre-allocates file (if enabled) with some space for later faster write access.
+        *
+        * @param       $type   Type of the file
+        * @return      void
+        * @throws      InvalidArgumentException        If a parameter is empty
+        * @throws      BadMethodCallException  If this->stackInstance is not properly set
+        */
+       protected function preAllocateFileByTypeLength (string $type, int $minimumBlockLength) {
+               // Is it enabled?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s,minimumBlockLength=%d - CALLED!', $type, $minimumBlockLength));
+               if (empty($type)) {
+                       // Empty type
+                       throw new InvalidArgumentException('Parameter "type" is empty');
+               } elseif ($minimumBlockLength < 1) {
+                       // Invalid block length
+                       throw new InvalidArgumentException(sprintf('Parameter minimumBlockLength=%d is not valid', $minimumBlockLength));
+               } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
+                       // Don't continue here.
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Not pre-allocating file.'));
+                       return;
+               }
+
+               // Get file size
+               $fileSize = $this->getFileSize();
+
+               // Calulcate seek position
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minimumBlockLength=%d,fileSize=%d', $minimumBlockLength, $fileSize));
+               $seekPosition = $this->getHeaderSize() + $minimumBlockLength * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count') + $fileSize ;
+
+               // Now simply write a NUL there. This will pre-allocate the file.
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->writeAtPosition(%d,NUL) ...', $seekPosition));
+               $this->writeAtPosition($seekPosition, chr(0));
+
+               // Is the seek position zero?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize=%d', $fileSize));
+               if ($fileSize == 0) {
+                       // Mark file as gaps-only
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->markGapsOnly(%s,%d) ...', $type, $minimumBlockLength));
+                       $this->markFileGapsOnly($type, $minimumBlockLength);
+               } else {
+                       // Analyze file structure
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->analyzeFileStructure() ...');
+                       $this->analyzeFileStructure();
+               }
+
+               // Rewind seek position
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...');
+               $this->rewind();
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
+       }
+
        /**
         * Checks wether the current entry is valid (not at the end of the file).
         * This method will return true if an emptied (nulled) entry has been found.
         *
         * @return      $isValid        Whether the next entry is valid
-        * @throws      UnexpectedValueException        If some value is not expected
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function isValid () {
-               // First calculate minimum block length
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               $length = $this->getIndexInstance()->calculateMinimumBlockLength();
-
-               // Short be more than zero!
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
+       protected function isValidByLength (int $length) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length));
                if ($length < 1) {
-                       // Throw UVE
-                       throw new UnexpectedValueException(sprintf('length=%d is not expected', $length));
+                       // Throw IAE
+                       throw new InvalidArgumentException(sprintf('Parameter length=%d is not valid', $length));
                }
 
                // Get current seek position
                $seekPosition = $this->determineSeekPosition();
 
                // Then try to read it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
                $data = $this->read($length);
 
                // If some bytes could be read, all is fine
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data[%s]()=%d', gettype($data), strlen($data)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data[%s]()=%d', gettype($data), strlen($data)));
                $isValid = ((is_string($data)) && (strlen($data) > 0));
 
                // Get header size
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d', intval($isValid)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d', intval($isValid)));
                $headerSize = $this->getHeaderSize();
 
                // Is the seek position at or beyond the header?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d,headerSize=%d', $seekPosition, $headerSize));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d,headerSize=%d', $seekPosition, $headerSize));
                if ($seekPosition >= $headerSize) {
                        // Seek back to old position
                        $isValid = ($isValid && $this->seek($seekPosition) === 0);
@@ -1002,7 +1024,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                }
 
                // Return result
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d - EXIT!', intval($isValid)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isValid=%d - EXIT!', intval($isValid)));
                return $isValid;
        }
 
@@ -1032,20 +1054,6 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
        }
 
-       /**
-        * Flushes the file header
-        *
-        * @return      void
-        */
-       public function flushFileHeader () {
-               // Call block instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-               $this->getIndexInstance()->flushFileHeader();
-
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
-       }
-
        /**
         * Searches for next suitable gap the given length of data can fit in
         * including padding bytes.
index 98eeede600dbc4b7cae60c488e18c70b48395b34..fd07bd6457277db073a2997c06d6726194fae3e4 100644 (file)
@@ -3,12 +3,15 @@
 namespace Org\Mxchange\CoreFramework\Filesystem\Index;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 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\Indexable;
 
 // Import SPL stuff
+use \BadMethodCallException;
+use \InvalidArgumentException;
 use \SplFileInfo;
 
 /**
@@ -65,11 +68,97 @@ class IndexFile extends BaseBinaryFile implements IndexableFile {
                // Init this abstract file
                $indexFileInstance->initFile($indexInfoInstance);
 
+               // Init counters and gaps array
+               $indexFileInstance->initCountersGapsArray();
+
                // Return the prepared instance
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: indexFileInstance=%s - EXIT!', $indexFileInstance->__toString()));
                return $indexFileInstance;
        }
 
+       /**
+        * Flushes the file header
+        *
+        * @return      void
+        * @throws      BadMethodCallException  If this->indexInstance is not properly set
+        */
+       public function flushFileHeader () {
+               // Validate call
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: CALLED!');
+               if (!($this->getIndexInstance() instanceof Indexable)) {
+                       // Index instance not set
+                       throw new BadMethodCallException('this->indexInstance[] is not properly set.');
+               }
+
+               // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Calling this->indexInstance->flushFileHeader() ...');
+               $this->getIndexInstance()->flushFileHeader();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!');
+       }
+
+       /**
+        * Pre-allocates file (if enabled) with some space for later faster write access.
+        *
+        * @param       $type   Type of the file
+        * @return      void
+        * @throws      InvalidArgumentException        If a parameter is empty
+        * @throws      BadMethodCallException  If this->indexInstance is not properly set
+        */
+       public function preAllocateFile (string $type) {
+               // Is it enabled?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: type=%s - CALLED!', $type));
+               if (empty($type)) {
+                       // Empty type
+                       throw new InvalidArgumentException('Parameter "type" is empty');
+               } elseif (!($this->getIndexInstance() instanceof Indexable)) {
+                       // Index instance not set
+                       throw new BadMethodCallException('this->indexInstance[] is not properly set.');
+               }
+
+               // Message to user
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Pre-allocating file ...');
+
+               // Calculate minimum block length
+               $minimumBlockLength = $this->getIndexInstance()->calculateMinimumBlockLength();
+
+               // Call protected method
+               $this->preAllocateFileByTypeLength($type, $minimumBlockLength);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!');
+       }
+
+       /**
+        * Checks wether the current entry is valid (not at the end of the file).
+        * This method will return true if an emptied (nulled) entry has been found.
+        *
+        * @return      $isValid        Whether the next entry is valid
+        * @throws      UnexpectedValueException        If some value is not expected
+        * @throws      BadMethodCallException  If this->indexInstance is not properly set
+        */
+       public function isValid () {
+               // Validate call
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: CALLED!');
+               if (!($this->getIndexInstance() instanceof Indexable)) {
+                       // Index instance not set
+                       throw new BadMethodCallException('this->indexInstance[] is not properly set.');
+               }
+
+               // Get length from index
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Calling this->indexInstance->calculateMinimumBlockLength() ...');
+               $length = $this->getIndexInstance()->calculateMinimumBlockLength();
+
+               // Call protected method
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Calling this->isValidByLength(%d) ...', $length));
+               $isValid = $this->isValidByLength($length);
+
+               // Return result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: isValid=%d - EXIT!', intval($isValid)));
+               return $isValid;
+       }
+
        /**
         * Writes given value to the file and returns a hash and gap position for it
         *
index ed3497d51e3521c5466e0c7970eef2008dba65db..d211aa1f1bef63abb10efec0e02306c0601c7ee5 100644 (file)
@@ -3,6 +3,7 @@
 namespace Org\Mxchange\CoreFramework\Stack\File;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Filesystem\Stack\FileStacker;
 use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
@@ -10,6 +11,7 @@ use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 
 // Import SPL stuff
+use \BadMethodCallException;
 use \InvalidArgumentException;
 use \SplFileInfo;
 
@@ -51,22 +53,108 @@ class StackFile extends BaseBinaryFile implements FileStacker {
         *
         * @param       $infoInstance   An instance of a SplFileInfo class
         * @param       $stackInstance  An instance of a StackableFile class
-        * @return      $fileInstance   An instance of this File class
+        * @return      $stackFileInstance      An instance of this File class
         */
        public final static function createStackFile (SplFileInfo $infoInstance, StackableFile $stackInstance) {
                // Get a new instance
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: infoInstance[%s]=%s,stackInstance=%s - CALLED!', get_class($infoInstance), $infoInstance, $stackInstance->__toString()));
-               $fileInstance = new StackFile();
+               $stackFileInstance = new StackFile();
 
                // Set stack instance here for callbacks
-               $fileInstance->setStackInstance($stackInstance);
+               $stackFileInstance->setStackInstance($stackInstance);
 
                // Init this abstract file
-               $fileInstance->initFile($infoInstance);
+               $stackFileInstance->initFile($infoInstance);
+
+               // Init counters and gaps array
+               $stackFileInstance->initCountersGapsArray();
 
                // Return the prepared instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: fileInstance=%s - EXIT!', $fileInstance->__toString()));
-               return $fileInstance;
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: stackFileInstance=%s - EXIT!', $stackFileInstance->__toString()));
+               return $stackFileInstance;
+       }
+
+       /**
+        * Flushes the file header
+        *
+        * @return      void
+        * @throws      BadMethodCallException  If this->stackInstance is not properly set
+        */
+       public function flushFileHeader () {
+               // Validate call
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: CALLED!');
+               if (!($this->getStackInstance() instanceof StackableFIle)) {
+                       // Index instance not set
+                       throw new BadMethodCallException('this->stackInstance[] is not properly set.');
+               }
+
+               // Call block instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: Calling this->indexInstance->flushFileHeader() ...');
+               $this->getStackInstance()->flushFileHeader();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: EXIT!');
+       }
+
+       /**
+        * Pre-allocates file (if enabled) with some space for later faster write access.
+        *
+        * @param       $type   Type of the file
+        * @return      void
+        * @throws      InvalidArgumentException        If a parameter is empty
+        * @throws      BadMethodCallException  If this->stackInstance is not properly set
+        */
+       public function preAllocateFile (string $type) {
+               // Is it enabled?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: type=%s - CALLED!', $type));
+               if (empty($type)) {
+                       // Empty type
+                       throw new InvalidArgumentException('Parameter "type" is empty');
+               } elseif (!($this->getStackInstance() instanceof StackableFile) && !($this->getStackInstance() instanceof StackableFile)) {
+                       // Index instance not set
+                       throw new BadMethodCallException('this->stackInstance[] and this->pointerInstance are not properly set.');
+               }
+
+               // Message to user
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: Pre-allocating file ...');
+
+               // Calculate minimum block length and get file size
+               $minimumBlockLength = $this->getStackInstance()->calculateMinimumBlockLength();
+
+               // Call protected method
+               $this->preAllocateFileByTypeLength($type, $minimumBlockLength);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: EXIT!');
+       }
+
+       /**
+        * Checks wether the current entry is valid (not at the end of the file).
+        * This method will return true if an emptied (nulled) entry has been found.
+        *
+        * @return      $isValid        Whether the next entry is valid
+        * @throws      UnexpectedValueException        If some value is not expected
+        * @throws      BadMethodCallException  If this->stackInstance is not properly set
+        */
+       public function isValid () {
+               // Validate call
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: CALLED!');
+               if (!($this->getStackInstance() instanceof StackableFile)) {
+                       // Index instance not set
+                       throw new BadMethodCallException('this->stackInstance[] is not properly set.');
+               }
+
+               // Get length from index
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: Calling this->stackInstance->calculateMinimumBlockLength() ...');
+               $length = $this->getStackInstance()->calculateMinimumBlockLength();
+
+               // Call protected method
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: Calling this->isValidByLength(%d) ...', $length));
+               $isValid = $this->isValidByLength($length);
+
+               // Return result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: isValid=%d - EXIT!', intval($isValid)));
+               return $isValid;
        }
 
        /**
index 1db19d8cdb04700c18325b50049ccff2baee0b73..6ac3f2c6dd3facde3bdf7baf5c0ed66694d44063 100644 (file)
@@ -53,15 +53,4 @@ abstract class BaseIndex extends BaseFrameworkSystem implements Indexable {
                parent::__construct($className);
        }
 
-       /**
-        * 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-INDEX: CALLED!');
-               /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
-       }
-
 }
index 84cd783432233fd3faa532ed16f23e06ac0f602f..073907dc076ed7217d44b9fc74e7da91402586d3 100644 (file)
@@ -315,8 +315,15 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
         * @return      $isLoaded       Whether this index has been loaded
         */
        public function isIndexLoaded () {
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+               // Is the file gaps-only?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
+               if ($this->getIteratorInstance()->isFileGapsOnly()) {
+                       // Then skip below code as this implies the file has been fully analyzed and "loaded"
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Underlaying file is gaps-only: Returning TRUE ... - EXIT!');
+                       return TRUE;
+               }
+
+               // Debug message
                /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
        }
 
index f6eaaae307c09619750e560be0008638f6d14398..ac47c77484d86fabde630fd6784abdbcf38f52ab 100644 (file)
@@ -227,11 +227,11 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
         */
        public function analyzeFileStructure () {
                // Just call the file instance
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
                $this->getBinaryFileInstance()->analyzeFileStructure();
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
        }
 
        /**
@@ -279,6 +279,7 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
                }
 
                // Just call the file instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->binaryFileInstance->preAllocateFile(%s) ...', $type));
                $this->getBinaryFileInstance()->preAllocateFile($type);
 
                // Trace message
@@ -550,4 +551,20 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
                return $seekPosition;
        }
 
+       /**
+        * Checks whether the abstracted file only contains gaps by counting all
+        * gaps' bytes together and compare it to total length.
+        *
+        * @return      $isGapsOnly             Whether the abstracted file only contains gaps
+        */
+       public function isFileGapsOnly () {
+               // Call file instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
+               $isGapsOnly = $this->getBinaryFileInstance()->isFileGapsOnly();
+
+               // Return position
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isGapsOnly=%d - EXIT!', $isGapsOnly));
+               return $isGapsOnly;
+       }
+
 }
index 6b4a8bfb0f58982df285a06ca2251ea08c089a96..4d236a0900993768c6a29428976cfd432da00a13 100644 (file)
@@ -242,6 +242,17 @@ abstract class BaseFileStack extends BaseStacker {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->iteratorInstance->initCountersGapsArray() ...');
                $this->getIteratorInstance()->initCountersGapsArray();
 
+               /*
+                * Get stack index instance. This can be used for faster
+                * "defragmentation" and startup.
+                */
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Creating index instance for fileInfoInstance[%s]=%s,type=%s ...', get_class($fileInfoInstance), $fileInfoInstance, $type));
+               $indexInstance = FileStackIndexFactory::createFileStackIndexInstance($fileInfoInstance, $type);
+
+               // And set it here
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: indexInstance=%s', $indexInstance->__toString()));
+               $this->setIndexInstance($indexInstance);
+
                // Is the file's header initialized?
                if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
                        // First pre-allocate a bit
@@ -257,17 +268,6 @@ abstract class BaseFileStack extends BaseStacker {
                /* 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
-                * "defragmentation" and startup.
-                */
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Creating index instance for fileInfoInstance[%s]=%s,type=%s ...', get_class($fileInfoInstance), $fileInfoInstance, $type));
-               $indexInstance = FileStackIndexFactory::createFileStackIndexInstance($fileInfoInstance, $type);
-
-               // And set it here
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: indexInstance=%s', $indexInstance->__toString()));
-               $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->isIndexLoaded() ...');
                if (!$this->getIndexInstance()->isIndexLoaded()) {
@@ -729,9 +729,9 @@ abstract class BaseFileStack extends BaseStacker {
                // Return gap position, hash and length of raw data
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,rawData()=%d - EXIT!', $stackName, $hash, strlen($rawData)));
                return [
-                       self::ARRAY_NAME_GAP_POSITION => $gapPosition,
-                       self::ARRAY_NAME_HASH         => $hash,
-                       self::ARRAY_NAME_DATA_LENGTH  => strlen($rawData),
+                       StackableFile::ARRAY_NAME_GAP_POSITION => $gapPosition,
+                       StackableFile::ARRAY_NAME_HASH         => $hash,
+                       StackableFile::ARRAY_NAME_DATA_LENGTH  => strlen($rawData),
                ];
        }
 
index 1272c20f3bd6308a8096ac06a1311f375b4c1e56..59be75a1173140cd0bf51796abc35b73d408d986 100644 (file)
@@ -35,7 +35,7 @@ interface LocalSearchCriteria extends Criteria {
         * @return      void
         * @todo        Find a nice casting here. (int) allows until and including 32766.
         */
-       function setLimit ($limit);
+       function setLimit (int $limit);
 
        /**
         * "Setter" for limit from a configuration entry
@@ -43,7 +43,7 @@ interface LocalSearchCriteria extends Criteria {
         * @param       $configEntry    The configuration entry which hold a number as limit
         * @return      void
         */
-       function setConfiguredLimit ($configEntry);
+       function setConfiguredLimit (string $configEntry);
 
        /**
         * Getter for limit
@@ -59,7 +59,7 @@ interface LocalSearchCriteria extends Criteria {
         * @return      void
         * @todo        Find a nice casting here. (int) allows until and including 32766.
         */
-       function setSkip ($skip);
+       function setSkip (int $skip);
 
        /**
         * Getter for skip
@@ -76,7 +76,8 @@ interface LocalSearchCriteria extends Criteria {
         * @param       $value                  Value to check
         * @param       $separator              Separator for "exploding" $value (default: ',')
         * @return      $isMatching             Whether the key/value is matching or excluded
+        * @throws      InvalidArgumentException        If parameter is invalid
         */
-       function isCriteriaMatching ($key, $value, $separator = ',');
+       function isCriteriaMatching (string $key, $value, string $separator = ',');
 
 }
index 5dcd2c4f198eb2fc09cc0af8bc71132fedd0eedc..04bc74993a781a5721cbd209edaea0f0e83cc9d5 100644 (file)
@@ -110,6 +110,14 @@ interface BinaryFile extends Filesystem {
         */
        function getFileSize ();
 
+       /**
+        * Checks whether the abstracted file only contains gaps by counting all
+        * gaps' bytes together and compare it to total length.
+        *
+        * @return      $isGapsOnly             Whether the abstracted file only contains gaps
+        */
+       function isFileGapsOnly();
+
        /**
         * Searches for next suitable gap the given length of data can fit in
         * including padding bytes.
index 64e49f53176d10750ad1fb89313bb561b205f903..65c57c30691b23d48d3cdc28dc69fbf186859a3d 100644 (file)
@@ -136,6 +136,30 @@ interface SeekableWritableFileIterator extends SeekableIterator {
         */
        function getFileSize ();
 
+       /**
+        * Getter for seek position
+        *
+        * @return      $seekPosition   Current seek position (stored here in object)
+        */
+       function getSeekPosition ();
+
+       /**
+        * 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
+        */
+       function searchNextGap (int $length);
+
+       /**
+        * Checks whether the abstracted file only contains gaps by counting all
+        * gaps' bytes together and compare it to total length.
+        *
+        * @return      $isGapsOnly             Whether the abstracted file only contains gaps
+        */
+       function isFileGapsOnly();
+
        /**
         * Writes data at given position
         *
@@ -155,13 +179,6 @@ interface SeekableWritableFileIterator extends SeekableIterator {
         */
        function writeAtPosition (int $seedPosition, string $data);
 
-       /**
-        * Getter for seek position
-        *
-        * @return      $seekPosition   Current seek position (stored here in object)
-        */
-       function getSeekPosition ();
-
        /**
         * Writes given value to the file and returns a hash and gap position for it
         *
@@ -181,13 +198,4 @@ interface SeekableWritableFileIterator extends SeekableIterator {
         */
        function writeDataToFreeGap (string $groupId, string $hash, string $encoded);
 
-       /**
-        * 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
-        */
-       function searchNextGap (int $length);
-
 }
index 57c7a646222ca81eabca006115016a4e07d6fbe8..a471b203cc24ce10c6b858f85d3891d3404d3439 100644 (file)
@@ -70,7 +70,7 @@ class CompressorChannel extends BaseMiddleware implements Registerable {
                        $directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($baseDir));
 
                        // Read all directories but no sub directories, .htaccess files and NullCompressor class
-                       while ($directoryEntry = $directoryInstance->readDirectoryExcept(array('.htaccess', 'class_NullCompressor.php'))) {
+                       while ($directoryEntry = $directoryInstance->readDirectoryExcept(array('class_NullCompressor.php'))) {
                                // Debug message
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('COMPRESSOR: directoryEntry=' . $directoryEntry);