*/
const INDEX_MAGIC = 'INDEXv0.1';
- /**
- * Separator for header data
- */
- const SEPARATOR_HEADER_DATA = 0x01;
-
- /**
- * Separator header->entries
- */
- const SEPARATOR_HEADER_ENTRIES = 0x02;
-
/**
* Protected constructor
*
*
* @return void
*/
- protected function readFileHeader () {
+ public function readFileHeader () {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
// First rewind to beginning as the header sits at the beginning ...
*
* @return void
*/
- protected function flushFileHeader () {
+ public function flushFileHeader () {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
// Put all informations together
}
/**
- * 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).
+ * Initializes this index
*
+ * @param $fileName File name of this index
* @return void
+ * @todo Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file.
*/
- private function analyzeFile () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+ protected function initIndex ($fileName) {
+ // Append index file extension
+ $fileName .= $this->getConfigInstance()->getConfigEntry('index_extension');
- // Make sure the file is initialized
- assert($this->isFileInitialized());
+ // Get a file i/o pointer instance for index file
+ $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileName, $this));
- // Init counters and gaps array
- $this->initCountersGapsArray();
+ // Get iterator instance
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance));
- // 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__));
+ // Is the instance implementing the right interface?
+ assert($iteratorInstance instanceof SeekableWritableFileIterator);
- // First rewind to the begining
- $this->getIteratorInstance()->rewind();
+ // Set iterator here
+ $this->setIteratorInstance($iteratorInstance);
- // Then try to load all entries
- while ($this->getIteratorInstance()->valid()) {
- // Go to next entry
- $this->getIteratorInstance()->next();
+ // Is the file's header initialized?
+ if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
+ // No, then create it (which may pre-allocate the index)
+ $this->getIteratorInstance()->createFileHeader();
- // Get current entry
- $current = $this->getIteratorInstance()->current();
+ // And pre-allocate a bit
+ $this->getIteratorInstance()->preAllocateFile('index');
+ } // END - if
- // Simply output it
- self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current=%s', __METHOD__, __LINE__, print_r($current, TRUE)));
- } // END - while
+ // Load the file header
+ $this->readFileHeader();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ // Count all entries in file
+ $this->getIteratorInstance()->analyzeFile();
}
/**
*
* @return $length Minimum length for one entry/block
*/
- public function caluclateMinimumBlockLength () {
+ public function calculateMinimumBlockLength () {
// Calulcate it
// @TODO Not finished yet
$length = 0;
}
/**
- * Initializes this index
+ * Close a file source and set it's instance to null and the file name
+ * to empty.
*
- * @param $fileName File name of this index
* @return void
- * @todo Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file.
+ * @throws UnsupportedOperationException If this method is called
*/
- protected function initIndex ($fileName) {
- // Append index file extension
- $fileName .= $this->getConfigInstance()->getConfigEntry('index_extension');
-
- // Get a file i/o pointer instance for index file
- $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileName));
-
- // Get iterator instance
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($fileInstance, $this));
-
- // Is the instance implementing the right interface?
- assert($iteratorInstance instanceof SeekableWritableFileIterator);
-
- // Set iterator here
- $this->setIteratorInstance($iteratorInstance);
-
- // Is the file's header initialized?
- if (!$this->isFileHeaderInitialized()) {
- // No, then create it (which may pre-allocate the index)
- $this->createFileHeader();
-
- // And pre-allocate a bit
- $this->preAllocateFile('index');
- } // END - if
+ public function closeFile () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
- // Load the file header
- $this->readFileHeader();
+ /**
+ * Determines whether the EOF has been reached
+ *
+ * @return $isEndOfFileReached Whether the EOF has been reached
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function isEndOfFileReached () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
- // Count all entries in file
- $this->analyzeFile();
+ /**
+ * Getter for file name
+ *
+ * @return $fileName The current file name
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function getFileName () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
}