+ /**
+ * 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: Invoking 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', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } 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
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Invoking this->preAllocateFileByTypeLength(%s,%d) ...', $type, $minimumBlockLength));
+ $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: Invoking this->indexInstance->calculateMinimumBlockLength() ...');
+ $length = $this->getIndexInstance()->calculateMinimumBlockLength();
+
+ // Call protected method
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Invoking 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;
+ }
+
+ /**
+ * 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
+ */
+ protected function readNextBlock () {
+ // First calculate minimum block length
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: this->seekPosition=%d - CALLED!', $this->getSeekPosition()));
+ $length = $this->getIndexInstance()->calculateMinimumBlockLength();
+
+ // Call protected method
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: Invoking parent::readNextBlockByLength(%d) ...', $length));
+ parent::readNextBlockByLength($length);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!');
+ }
+
+ /**
+ * Reads the file header
+ *
+ * @return void
+ */
+ public function readFileHeader () {
+ // Call index class' method
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: Invoking this->indexInstance->readIndexHeader() - CALLED!');
+ $this->getIndexInstance()->readIndexHeader();
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: EXIT!');
+ }
+