]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/index/file/class_BaseFileIndex.php
Continued:
[core.git] / framework / main / classes / index / file / class_BaseFileIndex.php
index e25f37b25f6447e7a36bd4d02da9441101cd6ac7..d8f697a38d91d5dfca7661aaf3e66eeb4a12e0e1 100644 (file)
@@ -65,17 +65,21 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
                $this->getIteratorInstance()->rewind();
 
+               // Get header size
+               $headerSize = $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize();
+
                // Then read it (see constructor for calculation)
-               $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: headerSize=%d', $headerSize));
+               $data = $this->getIteratorInstance()->getBinaryFileInstance()->read($headerSize);
 
                // Have all requested bytes been read?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
-               if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()));
+               if (strlen($data) != $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()) {
                        // Invalid header length
                        throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d',
                                strlen($data),
                                $data,
-                               $this->getIteratorInstance()->getHeaderSize()
+                               $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()
                        ));
                } elseif (empty(trim($data, chr(0)))) {
                        // Empty file header
@@ -94,7 +98,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
 
                // And update seek position
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->updateSeekPosition() ...');
-               $this->getIteratorInstance()->updateSeekPosition();
+               $this->getIteratorInstance()->getBinaryFileInstance()->updateSeekPosition();
 
                /*
                 * Now split it:
@@ -122,7 +126,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
                $header[1] = hex2bin($header[1]);
 
                // Set it here
-               $this->getIteratorInstance()->setHeader($header);
+               $this->getIteratorInstance()->getBinaryFileInstance()->setHeader($header);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
@@ -144,7 +148,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
                        chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
 
                        // Total entries
-                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
+                       str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
 
                        // Separator header<->entries
                        chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
@@ -152,20 +156,20 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
 
                // 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);
+               $this->getIteratorInstance()->getBinaryFileInstance()->writeAtPosition(0, $header);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
        }
 
        /**
-        * Initializes this index
+        * Initializes this file-based 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) {
+       protected function initFileIndex (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));
@@ -186,24 +190,24 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
 
                // Set it
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Setting headerSize=%d ...', $headerSize));
-               $this->getIteratorInstance()->setHeaderSize($headerSize);
+               $this->getIteratorInstance()->getBinaryFileInstance()->setHeaderSize($headerSize);
 
                // Init counters and gaps array
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->initCountersGapsArray() ...');
-               $this->getIteratorInstance()->initCountersGapsArray();
+               $this->getIteratorInstance()->getBinaryFileInstance()->initCountersGapsArray();
 
                // Default is not created
                $created = false;
 
                // Is the file's header initialized?
-               if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
+               if (!$this->getIteratorInstance()->getBinaryFileInstance()->isFileHeaderInitialized()) {
                        // First pre-allocate a bit
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->preAllocateFile(index) ...');
-                       $this->getIteratorInstance()->preAllocateFile('index');
+                       $this->getIteratorInstance()->getBinaryFileInstance()->preAllocateFile('index');
 
                        // Then write file header
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->createFileHeader() ...');
-                       $this->getIteratorInstance()->createFileHeader();
+                       $this->getIteratorInstance()->getBinaryFileInstance()->createFileHeader();
 
                        // Mark as freshly created
                        $created = true;
@@ -218,7 +222,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
                if (!$created) {
                        // Analyze file structure
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...');
-                       $this->getIteratorInstance()->analyzeFileStructure();
+                       $this->getIteratorInstance()->getBinaryFileInstance()->analyzeFileStructure();
                }
 
                // Trace message
@@ -256,7 +260,12 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
         */
        public function getFileSize () {
                // Call iterator's method
-               return $this->getIteratorInstance()->getFileSize();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+               $fileSize = $this->getIteratorInstance()->getBinaryFileInstance()->getFileSize();
+
+               // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: fileSize=%d - EXIT!', $fileSize));
+               return $fileSize;
        }
 
        /**
@@ -276,8 +285,8 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
                        throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
                }
 
-               // Partial stub!
-               $this->partialStub('length=' . $length);
+               // Debug message
+               /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: length=%d,this=%s', __METHOD__, __LINE__, $length, print_r($this, true)));
        }
 
        /**
@@ -302,7 +311,7 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
 
                // 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);
+               $status = $this->getIteratorInstance()->getBinaryFileInstance()->writeAtPosition($seekPosition, $dataStream);
 
                // Return status
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: status[%s]=%d - EXIT!', gettype($status), $status));
@@ -316,10 +325,10 @@ abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
         */
        public function isIndexLoaded () {
                // Is the file gaps-only?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
-               if ($this->getIteratorInstance()->isFileGapsOnly()) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+               if ($this->getIteratorInstance()->getBinaryFileInstance()->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!');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Underlaying file is gaps-only: Returning TRUE ... - EXIT!');
                        return TRUE;
                }