code is avoided, too).
Signed-off-by: Roland Häder <roland@mxchange.org>
* @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]
* @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]
protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
+
+ // Init counters and gaps array
+ $this->initCountersGapsArray();
}
/**
* @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);
}
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]
//* 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
*
$this->readFileHeader();
// Count all entries in file
- $this->analyzeFile();
+ $this->getIteratorInstance()->analyzeFile();
}
/**
* 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?
// 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]
* 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__));
//* 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.
*
$this->readFileHeader();
// Count all entries in file
- $this->analyzeFile();
+ $this->getIteratorInstance()->analyzeFile();
/*
* Get stack index instance. This can be used for faster