*/
const STACK_MAGIC = 'STACKv0.1';
- /**
- * Separator for header data
- */
- const SEPARATOR_HEADER_DATA = 0x01;
-
- /**
- * Separator header->entries
- */
- const SEPARATOR_HEADER_ENTRIES = 0x02;
-
- /**
- * Separator hash->name
- */
- const SEPARATOR_HASH_NAME = 0x03;
-
- /**
- * Length of name
- */
- const LENGTH_NAME = 10;
-
/**
* Protected constructor
*
* Reads the file header
*
* @return void
+ * @todo To hard assertions here, better rewrite them to exceptions
*/
- 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
);
// Write it to disk (header is always at seek position 0)
- $this->writeData(0, $header);
-
- //* 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__));
+ $this->writeData(0, $header, FALSE);
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
* @param $fileName File name of this stack
* @param $type Type of this stack (e.g. url_source for URL sources)
* @return void
+ * @todo Currently the stack file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole stack file.
*/
protected function initFileStack ($fileName, $type) {
- // Get a file i/o pointer instance for stack file
- $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName));
+ // Get a stack file instance
+ $fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileName, $this));
// Get iterator instance
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_io_iterator_class', array($pointerInstance));
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance));
// Is the instance implementing the right interface?
assert($iteratorInstance instanceof SeekableWritableFileIterator);
$this->readFileHeader();
// Count all entries in file
- $this->analyzeFile();
+ $this->getIteratorInstance()->analyzeFile();
/*
* Get stack index instance. This can be used for faster
$this->setIndexInstance($indexInstance);
}
- /**
- * Calculates minimum length for one entry
- *
- * @return $length Minimum length for one entry
- */
- protected function caluclateMinimumFileEntryLength () {
- // Calulcate it
- $length = self::getHashLength() + strlen(self::SEPARATOR_HASH_NAME) + self::LENGTH_NAME + 1;
-
- // Return it
- return $length;
- }
-
/**
* Adds a value to given stack
*
throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
}
+ /**
+ * Close a file source and set it's instance to null and the file name
+ * to empty.
+ *
+ * @return void
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public function closeFile () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Determines whether the EOF has been reached
+ *
+ * @return $isEndOfFileReached Whether the EOF has been reached
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public function isEndOfFileReached () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for file name
+ *
+ * @return $fileName The current file name
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public function getFileName () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
/**
* Getter for size of given stack (array count)
*
// Now, simply return the found count value, this must be up-to-date then!
return $this->getCounter();
}
+
+ /**
+ * Calculates minimum length for one entry/block
+ *
+ * @return $length Minimum length for one entry/block
+ */
+ public function calculateMinimumBlockLength () {
+ // Calulcate it
+ $length = self::getHashLength() + strlen(chr(self::SEPARATOR_HASH_NAME)) + self::LENGTH_NAME + 1 + strlen(self::getBlockSeparator());
+
+ // Return it
+ return $length;
+ }
}
// [EOF]