]> git.mxchange.org Git - core.git/commitdiff
Moved analyzeFile() to BaseFile where a much better place is (and duplicate
authorRoland Haeder <roland@mxchange.org>
Sat, 24 May 2014 11:26:18 +0000 (13:26 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 24 May 2014 11:26:18 +0000 (13:26 +0200)
code is avoided, too).

Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/interfaces/io/class_Pointer.php
inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php
inc/classes/main/file_directories/class_BaseFile.php
inc/classes/main/index/class_BaseIndex.php
inc/classes/main/iterator/io/class_FileIoIterator.php
inc/classes/main/stacker/file/class_BaseFileStack.php

index c17d881c219b746c470c443638d6c00306295be3..b0882b7a155f034b0155a51e5c99059eedf5b7c3 100644 (file)
@@ -52,6 +52,15 @@ interface Pointer extends FrameworkInterface {
         * @return      $isEndOfFileReached             Whether the EOF has been reached
         */
        function isEndOfFileReached ();
+
+       /**
+        * Analyzes entries in index file. This will count all found (and valid)
+        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
+        * only gaps are found, the file is considered as "virgin" (no entries).
+        *
+        * @return      void
+        */
+       function analyzeFile ();
 }
 
 // [EOF]
index abd1e583fbcf998cff8cea1441e780c73bf8ef19..263bba6887bef605933e8a9fbee5ec1bd5cd59cd 100644 (file)
@@ -54,6 +54,15 @@ interface SeekableWritableFileIterator extends SeekableIterator {
         * @return      $data   Data read from file
         */
        function read ($bytes);
+
+       /**
+        * Analyzes entries in index file. This will count all found (and valid)
+        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
+        * only gaps are found, the file is considered as "virgin" (no entries).
+        *
+        * @return      void
+        */
+       function analyzeFile ();
 }
 
 // [EOF]
index 7816e86645708ea95dce41107b50860ae0409767..fb60162627ffd747a23ac92c928ffebe15e152a7 100644 (file)
@@ -36,6 +36,9 @@ class BaseFile extends BaseFrameworkSystem {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
+
+               // Init counters and gaps array
+               $this->initCountersGapsArray();
        }
 
        /**
@@ -58,7 +61,6 @@ class BaseFile extends BaseFrameworkSystem {
         * @throws      UnsupportedOperationException   If this method is called
         */
        public final function getPointer () {
-               self::createDebugInstance(__CLASS__)->debugOutput('Unhandled ' . strlen($data) . ' bytes in this stream.');
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
@@ -193,6 +195,43 @@ class BaseFile extends BaseFrameworkSystem {
        public final function isEndOfFileReached () {
                return $this->getPointerInstance()->isEndOfFileReached();
        }
+
+       /**
+        * Analyzes entries in index file. This will count all found (and valid)
+        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
+        * only gaps are found, the file is considered as "virgin" (no entries).
+        *
+        * @return      void
+        */
+       public function analyzeFile () {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+
+               // Make sure the file is initialized
+               assert($this->isFileInitialized());
+
+               // Init counters and gaps array
+               $this->initCountersGapsArray();
+
+               // Output message (as this may take some time)
+               self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Analyzing file structure ... (this may take some time)', __METHOD__, __LINE__));
+
+               // First rewind to the begining
+               $this->rewind();
+
+               // Then try to load all entries
+               while ($this->valid()) {
+                       // Go to next entry
+                       $this->next();
+
+                       // Get current entry
+                       $current = $this->current();
+
+                       // Simply output it
+                       self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current=%s', __METHOD__, __LINE__, print_r($current, TRUE)));
+               } // END - while
+
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+       }
 }
 
 // [EOF]
index de0e5629ab411569ec73b1897d225f32e89919ec..0ee7b77c251cdeb08c49dda69acdf71bee129de5 100644 (file)
@@ -138,43 +138,6 @@ class BaseIndex extends BaseFrameworkSystem {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
        }
 
-       /**
-        * Analyzes entries in index file. This will count all found (and valid)
-        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
-        * only gaps are found, the file is considered as "virgin" (no entries).
-        *
-        * @return      void
-        */
-       private function analyzeFile () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
-               // Make sure the file is initialized
-               assert($this->isFileInitialized());
-
-               // Init counters and gaps array
-               $this->initCountersGapsArray();
-
-               // Output message (as this may take some time)
-               self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Analyzing file structure ... (this may take some time)', __METHOD__, __LINE__));
-
-               // First rewind to the begining
-               $this->getIteratorInstance()->rewind();
-
-               // Then try to load all entries
-               while ($this->getIteratorInstance()->valid()) {
-                       // Go to next entry
-                       $this->getIteratorInstance()->next();
-
-                       // Get current entry
-                       $current = $this->getIteratorInstance()->current();
-
-                       // Simply output it
-                       self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current=%s', __METHOD__, __LINE__, print_r($current, TRUE)));
-               } // END - while
-
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
-       }
-
        /**
         * Initializes this index
         *
@@ -211,7 +174,7 @@ class BaseIndex extends BaseFrameworkSystem {
                $this->readFileHeader();
 
                // Count all entries in file
-               $this->analyzeFile();
+               $this->getIteratorInstance()->analyzeFile();
        }
 
        /**
index 20d351f5e694d09b43376e8d1badc8b6f7368dfa..f2158c63eaf94a790caed9ebbb7ab3a08cc3ce4b 100644 (file)
@@ -134,6 +134,7 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato
         * Advances to next "block" of bytes
         *
         * @return      void
+        * @todo        This method will load large but empty files in a whole
         */
        public function next () {
                // Is there nothing to read?
@@ -282,6 +283,18 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato
                // Call pointer instance
                return $this->getPointerInstance()->read($bytes);
        }
+
+       /**
+        * Analyzes entries in index file. This will count all found (and valid)
+        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
+        * only gaps are found, the file is considered as "virgin" (no entries).
+        *
+        * @return      void
+        */
+       public function analyzeFile () {
+               // Just call the pointer instance
+               $this->getPointerInstance()->analyzeFile();
+       }
 }
 
 // [EOF]
index d16068d32d80ef3245a390e2f8ba0a626de8b49b..8e3ae4d8e11267a82923ec8e2381da7f5d61a312 100644 (file)
@@ -55,6 +55,7 @@ class BaseFileStack extends BaseStacker {
         * Reads the file header
         *
         * @return      void
+        * @todo        To hard assertions here, better rewrite them to exceptions
         */
        protected function readFileHeader () {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
@@ -150,43 +151,6 @@ class BaseFileStack extends BaseStacker {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
        }
 
-       /**
-        * Analyzes entries in stack file. This will count all found (and valid)
-        * entries, mark invalid as damaged and count gaps ("fragmentation"). If
-        * only gaps are found, the file is considered as "virgin" (no entries).
-        *
-        * @return      void
-        */
-       private function analyzeFile () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
-               // Make sure the file is initialized
-               assert($this->isFileInitialized());
-
-               // Init counters and gaps array
-               $this->initCountersGapsArray();
-
-               // Output message (as this may take some time)
-               self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Analyzing file structure ... (this may take some time)', __METHOD__, __LINE__));
-
-               // First rewind to the begining
-               $this->getIteratorInstance()->rewind();
-
-               // Then try to load all entries
-               while ($this->getIteratorInstance()->valid()) {
-                       // Go to next entry
-                       $this->getIteratorInstance()->next();
-
-                       // Get current entry
-                       $current = $this->getIteratorInstance()->current();
-
-                       // Simply output it
-                       self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current(%s)=%s', __METHOD__, __LINE__, strlen($current), print_r($current, TRUE)));
-               } // END - while
-
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
-       }
-
        /**
         * Initializes this file-based stack.
         *
@@ -221,7 +185,7 @@ class BaseFileStack extends BaseStacker {
                $this->readFileHeader();
 
                // Count all entries in file
-               $this->analyzeFile();
+               $this->getIteratorInstance()->analyzeFile();
 
                /*
                 * Get stack index instance. This can be used for faster