From: Roland Haeder Date: Sat, 31 May 2014 11:33:20 +0000 (+0200) Subject: These 3 methods are now moved to BaseFile. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3111839cd1c7877a5db1456dae218c71e07f2883;p=core.git These 3 methods are now moved to BaseFile. Signed-off-by: Roland Häder --- diff --git a/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php b/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php index b8b86be2..4cc67da6 100644 --- a/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php +++ b/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php @@ -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] diff --git a/inc/classes/main/file_directories/class_BaseFile.php b/inc/classes/main/file_directories/class_BaseFile.php index d228d796..a04877c8 100644 --- a/inc/classes/main/file_directories/class_BaseFile.php +++ b/inc/classes/main/file_directories/class_BaseFile.php @@ -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; } diff --git a/inc/classes/main/index/class_BaseIndex.php b/inc/classes/main/index/class_BaseIndex.php index 1b0b1533..45bbebce 100644 --- a/inc/classes/main/index/class_BaseIndex.php +++ b/inc/classes/main/index/class_BaseIndex.php @@ -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) diff --git a/inc/classes/main/iterator/file/class_FileIterator.php b/inc/classes/main/iterator/file/class_FileIterator.php index 712754a7..dce60bfd 100644 --- a/inc/classes/main/iterator/file/class_FileIterator.php +++ b/inc/classes/main/iterator/file/class_FileIterator.php @@ -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] diff --git a/inc/classes/main/stacker/file/class_BaseFileStack.php b/inc/classes/main/stacker/file/class_BaseFileStack.php index 8a9abe0b..abbcc775 100644 --- a/inc/classes/main/stacker/file/class_BaseFileStack.php +++ b/inc/classes/main/stacker/file/class_BaseFileStack.php @@ -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)