]> git.mxchange.org Git - core.git/commitdiff
These 3 methods are now moved to BaseFile.
authorRoland Haeder <roland@mxchange.org>
Sat, 31 May 2014 11:33:20 +0000 (13:33 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 31 May 2014 11:33:20 +0000 (13:33 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
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/file/class_FileIterator.php
inc/classes/main/stacker/file/class_BaseFileStack.php

index b8b86be26235afc2ca745a4ef72f61e766903fe3..4cc67da68ea7008a7bfd28c7b27cfd25778be199 100644 (file)
@@ -85,6 +85,31 @@ interface SeekableWritableFileIterator extends SeekableIterator {
         * @return      void
         */
        function preAllocateFile ($type);
+
+       /**
+        * Initializes counter for valid entries, arrays for damaged entries and
+        * an array for gap seek positions. If you call this method on your own,
+        * please re-analyze the file structure. So you are better to call
+        * analyzeFile() instead of this method.
+        *
+        * @return      void
+        */
+       function initCountersGapsArray ();
+
+       /**
+        * Getter for header size
+        *
+        * @return      $totalEntries   Size of file header
+        */
+       function getHeaderSize ();
+
+       /**
+        * Setter for header size
+        *
+        * @param       $headerSize             Size of file header
+        * @return      void
+        */
+       function setHeaderSize ($headerSize);
 }
 
 // [EOF]
index d228d796f60f5169bfea730a8cb741f191a58295..a04877c869ea40fbe7b8f60f526400f508c92a2c 100644 (file)
@@ -164,7 +164,7 @@ y    * @return      void
         *
         * @return      void
         */
-       protected function initCountersGapsArray () {
+       public function initCountersGapsArray () {
                // Init counter and seek position
                $this->setCounter(0);
                $this->setSeekPosition(0);
@@ -221,7 +221,7 @@ y    * @return      void
         * @param       $headerSize             Size of file header
         * @return      void
         */
-       protected final function setHeaderSize ($headerSize) {
+       public final function setHeaderSize ($headerSize) {
                // Set it
                $this->headerSize = $headerSize;
        }
index 1b0b153317321254242616e9bd4a8c1120525d6f..45bbebceef49527940185ca56126e4bfeb2c25ac 100644 (file)
@@ -36,17 +36,6 @@ class BaseIndex extends BaseFrameworkSystem {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
-
-               // Calculate header size
-               $this->setHeaderSize(
-                       strlen(self::INDEX_MAGIC) +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
-                       BaseFile::LENGTH_COUNT +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
-               );
-
-               // Init counters and gaps array
-               $this->initCountersGapsArray();
        }
 
        /**
@@ -61,11 +50,11 @@ class BaseIndex extends BaseFrameworkSystem {
                $this->getIteratorInstance()->rewind();
 
                // Then read it (see constructor for calculation)
-               $data = $this->getIteratorInstance()->read($this->getHeaderSize());
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getHeaderSize()));
+               $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getIteratorInstance()->getHeaderSize()));
 
                // Have all requested bytes been read?
-               assert(strlen($data) == $this->getHeaderSize());
+               assert(strlen($data) == $this->getIteratorInstance()->getHeaderSize());
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
 
                // Last character must be the separator
@@ -161,6 +150,17 @@ class BaseIndex extends BaseFrameworkSystem {
                // Set iterator here
                $this->setIteratorInstance($iteratorInstance);
 
+               // Calculate header size
+               $this->getIteratorInstance()->setHeaderSize(
+                       strlen(self::INDEX_MAGIC) +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
+                       BaseFile::LENGTH_COUNT +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
+               );
+
+               // Init counters and gaps array
+               $this->getIteratorInstance()->initCountersGapsArray();
+
                // Is the file's header initialized?
                if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
                        // No, then create it (which may pre-allocate the index)
index 712754a769054741e88627e9b98d4d7219786958..dce60bfd7edab3d1e9ea19a9c49b088cbf723bd8 100644 (file)
@@ -193,6 +193,40 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator
                // Just call the block instance
                $this->getBlockInstance()->preAllocateFile($type);
        }
+
+       /**
+        * Initializes counter for valid entries, arrays for damaged entries and
+        * an array for gap seek positions. If you call this method on your own,
+        * please re-analyze the file structure. So you are better to call
+        * analyzeFile() instead of this method.
+        *
+        * @return      void
+        */
+       public function initCountersGapsArray () {
+               // Call block instance
+               $this->getBlockInstance()->initCountersGapsArray();
+       }
+
+       /**
+        * Getter for header size
+        *
+        * @return      $totalEntries   Size of file header
+        */
+       public final function getHeaderSize () {
+               // Call block instance
+               return $this->getBlockInstance()->getHeaderSize();
+       }
+
+       /**
+        * Setter for header size
+        *
+        * @param       $headerSize             Size of file header
+        * @return      void
+        */
+       public final function setHeaderSize ($headerSize) {
+               // Call block instance
+               $this->getBlockInstance()->setHeaderSize($headerSize);
+       }
 }
 
 // [EOF]
index 8a9abe0bb15d934cd299a6e60b19781f419be06b..abbcc775c66ea1430307cd72c894015f3a4f9a46 100644 (file)
@@ -36,19 +36,6 @@ class BaseFileStack extends BaseStacker {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
-
-               // Calculate header size
-               $this->setHeaderSize(
-                       strlen(self::STACK_MAGIC) +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
-                       BaseFile::LENGTH_COUNT +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
-                       BaseFile::LENGTH_POSITION +
-                       strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
-               );
-
-               // Init counters and gaps array
-               $this->initCountersGapsArray();
        }
 
        /**
@@ -64,11 +51,11 @@ class BaseFileStack extends BaseStacker {
                $this->getIteratorInstance()->rewind();
 
                // Then read it (see constructor for calculation)
-               $data = $this->getIteratorInstance()->read($this->getHeaderSize());
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getHeaderSize()));
+               $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getIteratorInstance()->getHeaderSize()));
 
                // Have all requested bytes been read?
-               assert(strlen($data) == $this->getHeaderSize());
+               assert(strlen($data) == $this->getIteratorInstance()->getHeaderSize());
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
 
                // Last character must be the separator
@@ -172,6 +159,19 @@ class BaseFileStack extends BaseStacker {
                // Set iterator here
                $this->setIteratorInstance($iteratorInstance);
 
+               // Calculate header size
+               $this->getIteratorInstance()->setHeaderSize(
+                       strlen(self::STACK_MAGIC) +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
+                       BaseFile::LENGTH_COUNT +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
+                       BaseFile::LENGTH_POSITION +
+                       strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
+               );
+
+               // Init counters and gaps array
+               $this->getIteratorInstance()->initCountersGapsArray();
+
                // Is the file's header initialized?
                if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
                        // No, then create it (which may pre-allocate the stack)