$cfg->setConfigEntry('file_stack_pre_allocate_count', 10000);
// CFG: INDEX-INDEX-CLASS
-$cfg->setConfigEntry('file_stack_index_class', 'Org\Mxchange\CoreFramework\Index\Stack\FileStackIndex');
+$cfg->setConfigEntry('file_stack_index_class', 'Org\Mxchange\CoreFramework\Index\File\Stack\FileStackIndex');
// CFG: INDEX-PRE-ALLOCATE-ENABLED
$cfg->setConfigEntry('index_pre_allocate_enabled', 'Y');
* @return void
*/
protected function initWebOutputInstance () {
- // Get application instance
- $applicationInstance = ApplicationHelper::getSelfInstance();
-
// Init web output instance
- $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($applicationInstance));
+ $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class');
// Set it locally
$this->setWebOutputInstance($outputInstance);
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName($applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName() . '_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName($applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName() . '_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('confirm_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('confirm_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('home_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('home_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('login_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('login_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('login_failed_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('login_failed_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('logout_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('logout_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('register_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('register_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Construct the menu in every command. We could do this in BaseCommand class. But this means
// *every* command has a navigation system and that is want we don't want.
- $menuInstance = ObjectFactory::createObjectByConfiguredName('status_menu_class', array($applicationInstance));
+ $menuInstance = ObjectFactory::createObjectByConfiguredName('status_menu_class');
// Render the menu
$menuInstance->renderMenu();
// Import SPL stuff
use \InvalidArgumentException;
+use \OutOfBoundsException;
use \SeekableIterator;
/**
/**
* Seeks for to a specified position
*
- * @param $index Index to seek for
+ * @param $seekPosition Position to seek to
* @return void
+ * @throws OutOfBoundsException If the position is not seekable
*/
- public function seek (int $index) {
+ public function seek (int $seekPosition) {
+ // Validate parameter
+ if ($seekPosition < 0) {
+ // Throw exception
+ throw new OutOfBoundsException(sprintf('seekPositon=%d is not seekable', $seekPosition));
+ }
+
// Rewind to beginning
$this->rewind();
// Search for the entry
- while (($this->currentPos < $index) && ($this->valid())) {
+ while (($this->currentPos < $seekPosition) && ($this->valid())) {
// Continue on
$this->next();
}
use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
-use Org\Mxchange\CoreFramework\Filesystem\Block;
-use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
+use Org\Mxchange\CoreFramework\Index\Indexable;
use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
-use Org\Mxchange\CoreFramework\Traits\Index\Stack\IndexableStackTrait;
+use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
use Org\Mxchange\CoreFramework\Traits\Stack\StackableTrait;
// Import SPL stuff
use \BadMethodCallException;
use \InvalidArgumentException;
use \LogicException;
+use \OutOfBoundsException;
use \SplFileInfo;
use \UnexpectedValueException;
abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
// Load traits
use StackableTrait;
- use IndexableStackTrait;
+ use IndexableTrait;
/**
* Separator for header data
* @param $data Data to be written
* @param $flushHeader Whether to flush the header (default: flush)
* @return void
+ * @throws OutOfBoundsException If the position is not seekable
* @throws InvalidArgumentException If a parameter is invalid
*/
public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader)));
if ($seekPosition < 0) {
// Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
} elseif (empty($data)) {
// Empty data is invalid, too
throw new InvalidArgumentException('Parameter "data" is empty');
* @param $seekPosition Seek position in file
* @param $dataStream Data to be written
* @return mixed Number of writes bytes or false on error
+ * @throws OutOfBoundsException If the position is not seekable
* @throws InvalidArgumentException If a parameter is not valid
*/
public function writeAtPosition (int $seekPosition, string $dataStream) {
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
if ($seekPosition < 0) {
// Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
} elseif (empty($dataStream)) {
// Empty dataStream
throw new InvalidArgumentException('Parameter "dataStream" is empty');
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
// Calculate minimum length for one entry and get file size
- $minimumBlockLength = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+ $minimumBlockLength = $this->getIndexInstance()->calculateMinimumBlockLength();
$fileSize = $this->getFileSize();
// Calulcate seek position
* @param $offset Offset to seek to (or used as "base" for other seeks)
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
- * @throws InvalidArgumentException If a parameter is not valid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function seek (int $offset, int $whence = SEEK_SET) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: offset=%d,whence=%d - CALLED!', $offset, $whence));
if ($offset < 0) {
// No offset is smaller than zero
- throw new InvalidArgumentException(sprintf('offset=%d is not valid', $offset));
+ throw new OutOfBoundsException(sprintf('offset=%d is not valid', $offset));
}
// Call pointer instance
*
* @param $bytes Amount of bytes to read
* @return $data Data read from file
- * @throws InvalidArgumentException If a parameter is not valid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function read (int $bytes = 0) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: bytes=%d - CALLED!', $bytes));
if ($bytes < 0) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+ // Throw exception
+ throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
}
// Call pointer instance
// First calculate minimum block length
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d', $this->determineSeekPosition()));
- $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+ $length = $this->getIndexInstance()->calculateMinimumBlockLength();
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
// Read possibly back-buffered bytes from previous call of next().
public function isValid () {
// First calculate minimum block length
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+ $length = $this->getIndexInstance()->calculateMinimumBlockLength();
// Short be more than zero!
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
public function readFileHeader () {
// Is index set or stack?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- if ($this->getIndexableStackInstance() instanceof IndexableStack) {
+ if ($this->getIndexInstance() instanceof Indexable) {
// Call index instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexableStackInstance->readFileHeader() ...');
- $this->getIndexableStackInstance()->readFileHeader();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexInstance->readIndexHeader() ...');
+ $this->getIndexInstance()->readIndexHeader();
} elseif ($this->getStackInstance() instanceof StackableFile) {
// Call stacke instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->stackInstance->readFileHeader() ...');
- $this->getStackInstance()->readFileHeader();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->stackInstance->readStackHeader() ...');
+ $this->getStackInstance()->readStackHeader();
} else {
// Bad logic?
- throw new LogicException('Wether indexableStackInstance nor stackableFileInstance are set');
+ throw new LogicException('Wether indexInstance nor stackInstance are set');
}
// Trace message
public function flushFileHeader () {
// Call block instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- $this->getIndexableStackInstance()->flushFileHeader();
+ $this->getIndexInstance()->flushFileHeader();
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
use Org\Mxchange\CoreFramework\Filesystem\Index\IndexableFile;
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
+use Org\Mxchange\CoreFramework\Index\File\Stack\Indexable;
// Import SPL stuff
use \SplFileInfo;
* Creates an instance of this File class and prepares it for usage
*
* @param $fileInfoInstance An instance of a SplFileInfo class
- * @param $indexInstance An instance of a IndexableStack class
+ * @param $indexInstance An instance of a Indexable class
* @return $indexFileInstance An instance of an IndexableFile class
*/
- public final static function createIndexFile (SplFileInfo $fileInfoInstance, IndexableStack $indexInstance) {
+ public final static function createIndexFile (SplFileInfo $fileInfoInstance, Indexable $indexInstance) {
// Get a new instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,indexInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $indexInstance->__toString()));
$indexFileInstance = new IndexFile();
// Set file instance here for callbacks
- $indexFileInstance->setIndexableStackInstance($indexInstance);
+ $indexFileInstance->setIndexInstance($indexInstance);
// Expand file name with .idx
$indexInfoInstance = new SplFileInfo(sprintf('%s.idx', $fileInfoInstance->__toString()));
/**
* Writes given value to the file and returns a hash and gap position for it
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $value Value to be added to the stack
* @return $data Hash and gap position
- * @throws UnsupportedOperationException If this method is called
+ * @throws InvalidArgumentException If a parameter is not valid
*/
- public function writeValueToFile (string $groupId, $value) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: groupId=' . $groupId . ',value[' . gettype($value) . ']=' . print_r($value, true));
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ public function writeValueToFile (string $stackName, $value) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
+ if (empty($stackName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "stackName" is empty');
+ } elseif (is_object($value) || is_resource($value)) {
+ // Not wanted here
+ throw new InvalidArgumentException(sprintf('value[]=%s is not stackable in files', gettype($value)));
+ }
+
+ // Encode/convert the value into a "binary format"
+ $encoded = StringUtils::encodeData($value);
+
+ // Get a strong hash for the "encoded" data
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: encoded=%s', $encoded));
+ $hash = self::hash($encoded);
+
+ // Then write it to the next free gap
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: hash=%s', $hash));
+ $data = $this->getIndexInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
+
+ // Return info
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: data[]=%s - EXIT!', gettype($data)));
+ return $data;
}
/**
* Writes given raw data to the file and returns a gap position and length
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $hash Hash from encoded value
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
* @throws UnsupportedOperationException If this method is called
*/
- public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: groupId=' . $groupId . ',encoded()=' . strlen($encoded));
+ public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('INDEX-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
/**
* Writes given value to the file and returns a hash and gap position for it
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $value Value to be added to the stack
* @return $data Hash and gap position
* @throws InvalidArgumentException If a parameter is not valid
*/
- public function writeValueToFile (string $groupId, $value) {
+ public function writeValueToFile (string $stackName, $value) {
// Validate parameter
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: groupId=%s,value[]=%s - CALLED!', $groupId, gettype($value)));
- if (empty($groupId)) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('STACK-FILE: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
+ if (empty($stackName)) {
// Throw IAE
- throw new InvalidArgumentException('Parameter "groupId" is empty');
+ throw new InvalidArgumentException('Parameter "stackName" is empty');
} elseif (is_object($value) || is_resource($value)) {
// Not wanted here
throw new InvalidArgumentException(sprintf('value[]=%s is not stackable in files', gettype($value)));
$hash = self::hash($encoded);
// Then write it to the next free gap
- $data = $this->getStackInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
+ $data = $this->getStackInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
// Return info
return $data;
/**
* Writes given raw data to the file and returns a gap position and length
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $hash Hash from encoded value
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
* @throws UnsupportedOperationException If this method is called
*/
- public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: groupId=' . $groupId . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
+ public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('STACK-FILE: stackName=' . $stackName . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
// Import SPL stuff
-use \InvalidArgumentException;
+use \OutOfBoundsException;
use \SplFileObject;
/**
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-IO: offset=%d,whence=%d - CALLED!', $offset, $whence));
if ($offset < 0) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('offset=%d is not valid', $offset));
+ // Throw exception
+ throw new OutOfBoundsException(sprintf('offset=%d is not valid', $offset));
}
// Seek to position
*
* @param $bytes Amount of bytes to read or whole line (only text files)
* @return $data Data read from file
+ * @throws OutOfBoundsException If the position is not seekable
* @throws NullPointerException If the file pointer instance is not set by setFileObject()
- * @throws InvalidResourceException If there is no object being set
+ * @throws LogicException If $fileObject is not an object
*/
public function read (int $bytes = 0) {
// Some sanity checks
if ($bytes < 0) {
// Cannot be below zero
- throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+ throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
} elseif (is_null($this->getFileObject())) {
// Pointer not initialized
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
// Import SPL stuff
use \InvalidArgumentException;
use \SplFileInfo;
+use \OutOfBoundsException;
use \UnexpectedValueException;
/**
* @param $seekPosition Seek position in file
* @param $dataStream Data to be written
* @return mixed Number of writes bytes or false on error
+ * @throws OutOfBoundsException If the position is not seekable
* @throws InvalidArgumentException If a parameter is not valid
*/
public function writeAtPosition (int $seekPosition, string $dataStream) {
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
if ($seekPosition < 0) {
// Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
} elseif (empty($dataStream)) {
// Empty dataStream
throw new InvalidArgumentException('Parameter "dataStream" is empty');
* @param $seekPosition Seek position in file
* @param $whence "Seek mode" (see http://de.php.net/fseek)
* @return $status Status of this operation
- * @throws InvalidArgumentException If a parameter is not valid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function seek (int $seekPosition, int $whence = SEEK_SET) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
if ($seekPosition < 0) {
// Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
}
// Move the file pointer
*
* @param $bytes Amount of bytes to read
* @return $data Data read from file
- * @throws InvalidArgumentException If a parameter is invalid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function read (int $bytes = 0) {
// Validatre parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: bytes=%d - CALLED!', $bytes));
if ($bytes < 0) {
// Bytes cannot be lesser than zero
- throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+ throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
}
// Is $bytes bigger than zero?
}
/**
- * Reads the file header
+ * Checks if this index has been fully and properly loaded.
*
- * @return void
- * @throws UnexpectedValueException If header length or count of elements is invalid
+ * @return $isLoaded Whether this index has been loaded
*/
- public function readFileHeader () {
- // First rewind to beginning as the header sits at the beginning ...
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
- $this->getIteratorInstance()->rewind();
-
- // Then read it (see constructor for calculation)
- $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
-
- // Have all requested bytes been read?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
- if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
- // Invalid header length
- throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d',
- strlen($data),
- $data,
- $this->getIteratorInstance()->getHeaderSize()
- ));
- } elseif (empty(trim($data, chr(0)))) {
- // Empty file header
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: File header is empty - EXIT!');
- return;
- } elseif (substr($data, -1, 1) != chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) {
- // Bad last character
- throw new UnexpectedValueException(sprintf('data=%s does not end with "%s"',
- $data,
- chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
- ));
- }
-
- // Okay, then remove it
- $data = substr($data, 0, -1);
-
- // And update seek position
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->updateSeekPosition() ...');
- $this->getIteratorInstance()->updateSeekPosition();
-
- /*
- * Now split it:
- *
- * 0 => magic
- * 1 => total entries
- */
- $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data);
-
- // Check if the array has only 3 elements
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: header()=%d', count($header)));
- //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: header(%d)=%s', count($header), print_r($header, true)));
- if (count($header) != 2) {
- // Bad header
- throw new UnexpectedValueException(sprintf('header()=%d is not expected value 2', count($header)));
- } elseif ($header[0] !== Indexable::INDEX_MAGIC) {
- // Magic must be in first element
- throw new UnexpectedValueException(sprintf('header[0]=%s is not the expected magic (%s)', $header[0], Indexable::INDEX_MAGIC));
- } elseif (strlen($header[1]) != BaseBinaryFile::LENGTH_COUNT) {
- // Length of total entries not matching
- throw new UnexpectedValueException(sprintf('header[1](%d)=%s does not have expected length %d', strlen($header[1]), $header[1], BaseBinaryFile::LENGTH_COUNT));
- }
-
- // Decode count
- $header[1] = hex2bin($header[1]);
-
- // Set it here
- $this->getIteratorInstance()->setHeader($header);
-
+ public function isIndexLoaded () {
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
- }
-
- /**
- * Flushes the file header
- *
- * @return void
- */
- public function flushFileHeader () {
- // Put all informations together
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
- $header = sprintf('%s%s%s%s',
- // Magic
- Indexable::INDEX_MAGIC,
-
- // Separator header data
- chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
-
- // Total entries
- str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
-
- // Separator header<->entries
- chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
- );
-
- // Write it to disk (header is always at seek position 0)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header));
- $this->getIteratorInstance()->writeAtPosition(0, $header);
-
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
- }
-
- /**
- * Initializes this index
- *
- * @param $fileInfoInstance An instance of a SplFileInfo class
- * @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.
- */
- protected function initIndex (SplFileInfo $fileInfoInstance) {
- // Get a file i/o pointer instance for index file
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
- $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
-
- // Get iterator instance
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', [$fileInstance]);
-
- // Set iterator here
- $this->setIteratorInstance($iteratorInstance);
-
- // Calculate header size
- $headerSize = (
- strlen(Indexable::INDEX_MAGIC) +
- strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
- BaseBinaryFile::LENGTH_COUNT +
- strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES))
- );
-
- // Set it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: Setting headerSize=%d ...', $headerSize));
- $this->getIteratorInstance()->setHeaderSize($headerSize);
-
- // Init counters and gaps array
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->initCountersGapsArray() ...');
- $this->getIteratorInstance()->initCountersGapsArray();
-
- // Default is not created
- $created = false;
-
- // Is the file's header initialized?
- if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
- // First pre-allocate a bit
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->preAllocateFile(index) ...');
- $this->getIteratorInstance()->preAllocateFile('index');
-
- // Then write file header
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->createFileHeader() ...');
- $this->getIteratorInstance()->createFileHeader();
-
- // Mark as freshly created
- $created = true;
- }
-
- // Load the file header
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->readFileHeader() ...');
- $this->readFileHeader();
-
- // Freshly created?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: created=%d', intval($created)));
- if (!$created) {
- // Analyze file structure
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...');
- $this->getIteratorInstance()->analyzeFileStructure();
- }
-
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
- }
-
- /**
- * Calculates minimum length for one entry/block
- *
- * @return $length Minimum length for one entry/block
- */
- public function calculateMinimumBlockLength () {
- // Is it "cached"?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
- if (self::$minimumBlockLength == 0) {
- // Calulcate it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Calculating ...');
- self::$minimumBlockLength = (
- // Type
- BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) +
- // Position
- BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES))
- );
- }
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: self::minimumBlockLength=%d - EXIT!', self::$minimumBlockLength));
- return self::$minimumBlockLength;
- }
-
- /**
- * 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);
- }
-
- /**
- * 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
- * analyzeFileStructure() instead of this method.
- *
- * @return void
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public function initCountersGapsArray () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Getter for header size
- *
- * @return $totalEntries Size of file header
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public final function getHeaderSize () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Setter for header size
- *
- * @param $headerSize Size of file header
- * @return void
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public final function setHeaderSize (int $headerSize) {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Getter for header array
- *
- * @return $totalEntries Size of file header
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public final function getHeader () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Setter for header
- *
- * @param $header Array for a file header
- * @return void
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public final function setHeader (array $header) {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Updates seekPosition attribute from file to avoid to much access on file.
- *
- * @return void
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public function updateSeekPosition () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Getter for total entries
- *
- * @return $totalEntries Total entries in this file
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public final function getCounter () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * "Getter" for file size
- *
- * @return $fileSize Size of currently loaded file
- */
- public function getFileSize () {
- // Call iterator's method
- return $this->getIteratorInstance()->getFileSize();
- }
-
- /**
- * Writes data at given position
- *
- * @param $seekPosition Seek position
- * @param $data Data to be written
- * @param $flushHeader Whether to flush the header (default: flush)
- * @return void
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('seekPosition=%s,data[]=%s,flushHeader=%d - CALLED!', $seekPosition, gettype($data), intval($flushHeader)));
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Writes given value to the file and returns a hash and gap position for it
- *
- * @param $groupId Group identifier
- * @param $value Value to be added to the stack
- * @return $data Hash and gap position
- * @throws UnsupportedOperationException If this method is called
- */
- public function writeValueToFile (string $groupId, $value) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('groupId=%s,value[%s]=%s - CALLED!', $groupId, gettype($value), print_r($value, true)));
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Writes given raw data to the file and returns a gap position and length
- *
- * @param $groupId Group identifier
- * @param $hash Hash from encoded value
- * @param $encoded Encoded value to be written to the file
- * @return $data Gap position and length of the raw data
- */
- public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('groupId=%s,hash=%s,encoded()=%d - CALLED!', $groupId, $hash, strlen($encoded)));
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
}
}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
+use Org\Mxchange\CoreFramework\Index\BaseIndex;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
+
+// Import SPL stuff
+use \OutOfBoundsException;
+use \SplFileInfo;
+use \UnexpectedValueException;
+
+/**
+ * A general file-based index class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+abstract class BaseFileIndex extends BaseIndex implements FileIndexer {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Reads the file header
+ *
+ * @return void
+ * @throws UnexpectedValueException If header length or count of elements is invalid
+ */
+ public function readIndexHeader () {
+ // First rewind to beginning as the header sits at the beginning ...
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+ $this->getIteratorInstance()->rewind();
+
+ // Then read it (see constructor for calculation)
+ $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+
+ // Have all requested bytes been read?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
+ if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
+ // Invalid header length
+ throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d',
+ strlen($data),
+ $data,
+ $this->getIteratorInstance()->getHeaderSize()
+ ));
+ } elseif (empty(trim($data, chr(0)))) {
+ // Empty file header
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: File header is empty - EXIT!');
+ return;
+ } elseif (substr($data, -1, 1) != chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) {
+ // Bad last character
+ throw new UnexpectedValueException(sprintf('data=%s does not end with "%s"',
+ $data,
+ chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
+ ));
+ }
+
+ // Okay, then remove it
+ $data = substr($data, 0, -1);
+
+ // And update seek position
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->updateSeekPosition() ...');
+ $this->getIteratorInstance()->updateSeekPosition();
+
+ /*
+ * Now split it:
+ *
+ * 0 => magic
+ * 1 => total entries
+ */
+ $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data);
+
+ // Check if the array has only 3 elements
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: header()=%d', count($header)));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: header(%d)=%s', count($header), print_r($header, true)));
+ if (count($header) != 2) {
+ // Bad header
+ throw new UnexpectedValueException(sprintf('header()=%d is not expected value 2', count($header)));
+ } elseif ($header[0] !== Indexable::INDEX_MAGIC) {
+ // Magic must be in first element
+ throw new UnexpectedValueException(sprintf('header[0]=%s is not the expected magic (%s)', $header[0], Indexable::INDEX_MAGIC));
+ } elseif (strlen($header[1]) != BaseBinaryFile::LENGTH_COUNT) {
+ // Length of total entries not matching
+ throw new UnexpectedValueException(sprintf('header[1](%d)=%s does not have expected length %d', strlen($header[1]), $header[1], BaseBinaryFile::LENGTH_COUNT));
+ }
+
+ // Decode count
+ $header[1] = hex2bin($header[1]);
+
+ // Set it here
+ $this->getIteratorInstance()->setHeader($header);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
+ }
+
+ /**
+ * Flushes the file header
+ *
+ * @return void
+ */
+ public function flushFileHeader () {
+ // Put all informations together
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+ $header = sprintf('%s%s%s%s',
+ // Magic
+ Indexable::INDEX_MAGIC,
+
+ // Separator header data
+ chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
+
+ // Total entries
+ str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
+
+ // Separator header<->entries
+ chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
+ );
+
+ // Write it to disk (header is always at seek position 0)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header));
+ $this->getIteratorInstance()->writeAtPosition(0, $header);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
+ }
+
+ /**
+ * Initializes this index
+ *
+ * @param $fileInfoInstance An instance of a SplFileInfo class
+ * @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.
+ */
+ protected function initIndex (SplFileInfo $fileInfoInstance) {
+ // Get a file i/o pointer instance for index file
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
+ $fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
+
+ // Get iterator instance
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', [$fileInstance]);
+
+ // Set iterator here
+ $this->setIteratorInstance($iteratorInstance);
+
+ // Calculate header size
+ $headerSize = (
+ strlen(Indexable::INDEX_MAGIC) +
+ strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
+ BaseBinaryFile::LENGTH_COUNT +
+ strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES))
+ );
+
+ // Set it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Setting headerSize=%d ...', $headerSize));
+ $this->getIteratorInstance()->setHeaderSize($headerSize);
+
+ // Init counters and gaps array
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->initCountersGapsArray() ...');
+ $this->getIteratorInstance()->initCountersGapsArray();
+
+ // Default is not created
+ $created = false;
+
+ // Is the file's header initialized?
+ if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
+ // First pre-allocate a bit
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->preAllocateFile(index) ...');
+ $this->getIteratorInstance()->preAllocateFile('index');
+
+ // Then write file header
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->createFileHeader() ...');
+ $this->getIteratorInstance()->createFileHeader();
+
+ // Mark as freshly created
+ $created = true;
+ }
+
+ // Load the file header
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->readIndexHeader() ...');
+ $this->readIndexHeader();
+
+ // Freshly created?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: created=%d', intval($created)));
+ if (!$created) {
+ // Analyze file structure
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...');
+ $this->getIteratorInstance()->analyzeFileStructure();
+ }
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
+ }
+
+ /**
+ * Calculates minimum length for one entry/block
+ *
+ * @return $length Minimum length for one entry/block
+ */
+ public function calculateMinimumBlockLength () {
+ // Is it "cached"?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+ if (self::$minimumBlockLength == 0) {
+ // Calulcate it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calculating ...');
+ self::$minimumBlockLength = (
+ // Type
+ BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) +
+ // Position
+ BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES))
+ );
+ }
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: self::minimumBlockLength=%d - EXIT!', self::$minimumBlockLength));
+ return self::$minimumBlockLength;
+ }
+
+ /**
+ * "Getter" for file size
+ *
+ * @return $fileSize Size of currently loaded file
+ */
+ public function getFileSize () {
+ // Call iterator's method
+ return $this->getIteratorInstance()->getFileSize();
+ }
+
+ /**
+ * Searches for next suitable gap the given length of data can fit in
+ * including padding bytes.
+ *
+ * @param $length Length of raw data
+ * @return $seekPosition Found next gap's seek position
+ * @throws InvalidArgumentException If the parameter is not valid
+ * @todo Unfinished work
+ */
+ public function searchNextGap (int $length) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: length=%d - CALLED!', $length));
+ if ($length <= 0) {
+ // Throw IAE
+ throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
+ }
+
+ // Partial stub!
+ $this->partialStub('length=' . $length);
+ }
+
+ /**
+ * Writes at given position by seeking to it.
+ *
+ * @param $seekPosition Seek position in file
+ * @param $dataStream Data to be written
+ * @return mixed Number of writes bytes or false on error
+ * @throws OutOfBoundsException If the position is not seekable
+ * @throws InvalidArgumentException If a parameter is not valid
+ */
+ public function writeAtPosition (int $seekPosition, string $dataStream) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
+ if ($seekPosition < 0) {
+ // Invalid seek position
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ } elseif (empty($dataStream)) {
+ // Empty dataStream
+ throw new InvalidArgumentException('Parameter "dataStream" is empty');
+ }
+
+ // Call iterated object's method
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Calling this->iteratorInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
+ $status = $this->getIteratorInstance()->writeAtPosition($seekPosition, $dataStream);
+
+ // Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: status[%s]=%d - EXIT!', gettype($status), $status));
+ return $status;
+ }
+
+ /**
+ * Checks if this index has been fully and properly loaded.
+ *
+ * @return $isLoaded Whether this index has been loaded
+ */
+ public function isIndexLoaded () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+ /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
+ }
+
+}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File\Stack;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
+use Org\Mxchange\CoreFramework\Index\File\BaseFileIndex;
+use Org\Mxchange\CoreFramework\Index\File\Stack\IndexableStack;
+use Org\Mxchange\CoreFramework\Index\Indexable;
+use Org\Mxchange\CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+use \SplFileInfo;
+use \UnexpectedValueException;
+
+/**
+ * A FileStack index class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class FileStackIndex extends BaseFileIndex implements IndexableStack, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this Index class and prepares it for usage
+ *
+ * @param $fileInfoInstance An instance of a SplFileInfo class
+ * @return $indexInstance An instance of this Index class
+ */
+ public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
+ // Get a new instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
+ $indexInstance = new FileStackIndex();
+
+ // Initialize index
+ $indexInstance->initIndex($fileInfoInstance);
+
+ // Return the prepared instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: indexInstance=%s - EXIT!', $indexInstance->__toString()));
+ return $indexInstance;
+ }
+
+ /**
+ * Adds given data's hash to an index file
+ *
+ * @param $stackName Name of stack to add hash for
+ * @param $data Hash and gap position to be added to the index
+ * @return void
+ * @throws InvalidArgumentException If a parameter is not valid
+ * @throws UnexpectedValueException If an invalid gap position is being returned
+ */
+ public function addHashedDataToIndex (string $stackName, array $data) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,data()=%d - CALLED!', $stackName, count($data)));
+ if (empty($stackName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "stackName" is empty');
+ } elseif (count($data) == 0) {
+ // Throw it again
+ throw new InvalidArgumentException('Parameter "data" is an empty array');
+ } elseif (!isset($data[StackableFile::ARRAY_NAME_HASH])) {
+ // Important array element missing
+ throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_HASH]));
+ } elseif (!isset($data[StackableFile::ARRAY_NAME_GAP_POSITION])) {
+ // Important array element missing
+ throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_GAP_POSITION]));
+ } elseif (!isset($data[StackableFile::ARRAY_NAME_DATA_LENGTH])) {
+ // Important array element missing
+ throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_DATA_LENGTH]));
+ }
+
+ // Raw data been written to the file
+ $rawData = sprintf('%s%s%s%s%s%s%s',
+ $stackName,
+ Indexable::SEPARATOR_GROUP_HASH,
+ hex2bin($data[StackableFile::ARRAY_NAME_HASH]),
+ Indexable::SEPARATOR_HASH_GAP_POSITION,
+ $data[StackableFile::ARRAY_NAME_GAP_POSITION],
+ Indexable::SEPARATOR_GAP_LENGTH,
+ $data[StackableFile::ARRAY_NAME_DATA_LENGTH]
+ );
+
+ // Search for next free gap
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,hash=%s,rawData()=%d', $stackName, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
+ $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
+
+ // Gap position cannot be smaller or equal than header length
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,hash=%s,gapPosition=%s', $stackName, $data[StackableFile::ARRAY_NAME_HASH], $gapPosition));
+ if ($gapPosition <= ($this->getIteratorInstance()->getHeaderSize() + 1)) {
+ // Not valid gap position returned
+ throw new UnexpectedValueException(sprintf('gapPosition[%s]=%d is smaller or equal headerSize+1=%d', gettype($gapPosition), $gapPosition, ($this->getIteratorInstance()->getHeaderSize() + 1)));
+ }
+
+ // Then write the data at that gap
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: Calling this->iteratorInstance->writeData(%d,%s) ...', $gapPosition, $rawData));
+ $this->getIteratorInstance()->writeData($gapPosition, $rawData);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: stackName=%s,hash=%s,rawData()=%d - EXIT!', $stackName, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
+ }
+
+}
+++ /dev/null
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Index\Stack;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
-use Org\Mxchange\CoreFramework\Index\BaseIndex;
-use Org\Mxchange\CoreFramework\Index\Indexable;
-use Org\Mxchange\CoreFramework\Registry\Registerable;
-use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
-
-// Import SPL stuff
-use \InvalidArgumentException;
-use \SplFileInfo;
-use \UnexpectedValueException;
-
-/**
- * A FileStack index class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class FileStackIndex extends BaseIndex implements IndexableStack, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this Index class and prepares it for usage
- *
- * @param $fileInfoInstance An instance of a SplFileInfo class
- * @return $indexInstance An instance of this Index class
- */
- public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
- // Get a new instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
- $indexInstance = new FileStackIndex();
-
- // Initialize index
- $indexInstance->initIndex($fileInfoInstance);
-
- // Return the prepared instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: indexInstance=%s - EXIT!', $indexInstance->__toString()));
- return $indexInstance;
- }
-
- /**
- * Adds given data's hash to an index file
- *
- * @param $groupId Name of stack to add hash for
- * @param $data Hash and gap position to be added to the index
- * @return void
- * @throws InvalidArgumentException If a parameter is not valid
- * @throws UnexpectedValueException If an invalid gap position is being returned
- */
- public function addHashedDataToIndex (string $groupId, array $data) {
- // Validate parameter
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,data()=%d - CALLED!', $groupId, count($data)));
- if (empty($groupId)) {
- // Throw IAE
- throw new InvalidArgumentException('Parameter "groupId" is empty');
- } elseif (count($data) == 0) {
- // Throw it again
- throw new InvalidArgumentException('Parameter "data" is an empty array');
- } elseif (!isset($data[StackableFile::ARRAY_NAME_HASH])) {
- // Important array element missing
- throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_HASH]));
- } elseif (!isset($data[StackableFile::ARRAY_NAME_GAP_POSITION])) {
- // Important array element missing
- throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_GAP_POSITION]));
- } elseif (!isset($data[StackableFile::ARRAY_NAME_DATA_LENGTH])) {
- // Important array element missing
- throw new InvalidArgumentException(sprintf('data[%s] not found', $data[StackableFile::ARRAY_NAME_DATA_LENGTH]));
- }
-
- // Raw data been written to the file
- $rawData = sprintf('%s%s%s%s%s%s%s',
- $groupId,
- Indexable::SEPARATOR_GROUP_HASH,
- hex2bin($data[StackableFile::ARRAY_NAME_HASH]),
- Indexable::SEPARATOR_HASH_GAP_POSITION,
- $data[StackableFile::ARRAY_NAME_GAP_POSITION],
- Indexable::SEPARATOR_GAP_LENGTH,
- $data[StackableFile::ARRAY_NAME_DATA_LENGTH]
- );
-
- // Search for next free gap
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d', $groupId, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
- $gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
-
- // Gap position cannot be smaller or equal than header length
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gapPosition=%s', $groupId, $data[StackableFile::ARRAY_NAME_HASH], $gapPosition));
- if ($gapPosition <= ($this->getIteratorInstance()->getHeaderSize() + 1)) {
- // Not valid gap position returned
- throw new UnexpectedValueException(sprintf('gapPosition[%s]=%d is smaller or equal headerSize+1=%d', gettype($gapPosition), $gapPosition, ($this->getIteratorInstance()->getHeaderSize() + 1)));
- }
-
- // Then write the data at that gap
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: Calling this->iteratorInstance->writeData(%d,%s) ...', $gapPosition, $rawData));
- $this->getIteratorInstance()->writeData($gapPosition, $rawData);
-
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $data[StackableFile::ARRAY_NAME_HASH], strlen($rawData)));
- }
-
- /**
- * Searches for next suitable gap the given length of data can fit in
- * including padding bytes.
- *
- * @param $length Length of raw data
- * @return $seekPosition Found next gap's seek position
- * @throws InvalidArgumentException If the parameter is not valid
- * @todo Unfinished work
- */
- public function searchNextGap (int $length) {
- // Validate parameter
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: length=%d - CALLED!', $length));
- if ($length <= 0) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
- }
-
- // Partial stub!
- $this->partialStub('length=' . $length);
- }
-
- /**
- * Writes at given position by seeking to it.
- *
- * @param $seekPosition Seek position in file
- * @param $dataStream Data to be written
- * @return mixed Number of writes bytes or false on error
- * @throws InvalidArgumentException If a parameter is not valid
- */
- public function writeAtPosition (int $seekPosition, string $dataStream) {
- // Validate parameter
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
- if ($seekPosition < 0) {
- // Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
- } elseif (empty($dataStream)) {
- // Empty dataStream
- throw new InvalidArgumentException('Parameter "dataStream" is empty');
- }
-
- // Call iterated object's method
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: Calling this->iteratorInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
- $status = $this->getIteratorInstance()->writeAtPosition($seekPosition, $dataStream);
-
- // Return status
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: status[%s]=%d - EXIT!', gettype($status), $status));
- return $status;
- }
-
- /**
- * Checks if this index file has been fully and properly loaded.
- *
- * @return $isLoaded Whether this index file has been loaded
- */
- public function isIndexFileLoaded () {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-STACK-INDEX: CALLED!');
- /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, true)));
- }
-
-}
// Import SPL stuff
use \BadMethodCallException;
use \InvalidArgumentException;
+use \OutOfBoundsException;
/**
* A file iterator
* @param $seekPosition Seek position in file
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of this operation
- * @throws InvalidArgumentException If a parameter is not valid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function seek (int $seekPosition, int $whence = SEEK_SET) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
if ($seekPosition < 0) {
// Throw IAE
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
}
// Call file instance
*
* @param $bytes Amount of bytes to read
* @return $data Data read from file
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function read (int $bytes = 0) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: bytes=%d - CALLED!', $bytes));
if ($bytes < 0) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+ // Throw exception
+ throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
}
// Call file instance
* @param $data Data to be written
* @param $flushHeader Whether to flush the header (default: flush)
* @return void
+ * @throws OutOfBoundsException If the position is not seekable
* @throws InvalidArgumentException If a parameter is not valid
*/
public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,data(%d)=%s,flushHeader=%d - CALLED!', $seekPosition, strlen($data), $data, intval($flushHeader)));
if ($seekPosition < 0) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+ // Throw exception
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
} elseif (empty($data)) {
- // Throw it again
+ // Throw IAE
throw new InvalidArgumentException('Parameter "data" is empty');
}
* @param $seekPosition Seek position in file
* @param $dataStream Data to be written
* @return mixed Number of writes bytes or false on error
+ * @throws OutOfBoundsException If the position is not seekable
* @throws InvalidArgumentException If a parameter is not valid
*/
public function writeAtPosition (int $seekPosition, string $dataStream) {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
if ($seekPosition < 0) {
// Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
} elseif (empty($dataStream)) {
// Empty dataStream
throw new InvalidArgumentException('Parameter "dataStream" is empty');
/**
* Writes given value to the file and returns a hash and gap position for it
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $value Value to be added to the stack
* @return $data Hash and gap position
* @throws InvalidArgumentException If a parameter is not valid
*/
- public function writeValueToFile (string $groupId, $value) {
+ public function writeValueToFile (string $stackName, $value) {
// Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,value[]=%s - CALLED!', $groupId, gettype($value)));
- if (empty($groupId)) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
+ if (empty($stackName)) {
// Throw IAE
- throw new InvalidArgumentException('Parameter "groupId" is empty');
+ throw new InvalidArgumentException('Parameter "stackName" is empty');
} elseif (is_resource($value) || is_object($value)) {
// Resources and objects are nothing for file-based indexes (mostly)
throw new InvalidArgumentException(sprintf('value[]=%s is not supported by file-based indexes', gettype($value)));
}
// Call file instance
- $data = $this->getBinaryFileInstance()->writeValueToFile($groupId, $value);
+ $data = $this->getBinaryFileInstance()->writeValueToFile($stackName, $value);
// Return data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
/**
* Writes given raw data to the file and returns a gap position and length
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $hash Hash from encoded value
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
*/
- public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
+ public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
// Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,hash=%s,encoded(%d)=%s - CALLED!', $groupId, $hash, strlen($encoded), $encoded));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,hash=%s,encoded(%d)=%s - CALLED!', $stackName, $hash, strlen($encoded), $encoded));
// Call file instance
- $data = $this->getBinaryFileInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
+ $data = $this->getBinaryFileInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
// Return data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
print trim($outStream) . PHP_EOL;
}
- /**
- * Determines seek position
- *
- * @return $seekPosition Current seek position
- * @throws UnsupportedOperationException If this method is called
- */
- public function determineSeekPosition () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Seek to given offset (default) or other possibilities as fseek() gives.
- *
- * @param $offset Offset to seek to (or used as "base" for other seeks)
- * @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of file seek: 0 = success, -1 = failed
- * @throws UnsupportedOperationException If this method is called
- */
- public function seek (int $offset, int $whence = SEEK_SET) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- * @throws UnsupportedOperationException If this method is called
- */
- public function size () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
}
* @param $loggerClassName Class name this output class is being used for logging
* @return void
*/
- public final function setLoggerClassName ($loggerClassName) {
+ public final function setLoggerClassName (string $loggerClassName) {
$this->loggerClassName = $loggerClassName;
}
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
- /**
- * Determines seek position
- *
- * @return $seekPosition Current seek position
- * @throws UnsupportedOperationException If this method is called
- */
- public function determineSeekPosition () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Seek to given offset (default) or other possibilities as fseek() gives.
- *
- * @param $offset Offset to seek to (or used as "base" for other seeks)
- * @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of file seek: 0 = success, -1 = failed
- * @throws UnsupportedOperationException If this method is called
- */
- public function seek (int $offset, int $whence = SEEK_SET) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- * @throws UnsupportedOperationException If this method is called
- */
- public function size () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
}
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
- /**
- * Determines for seek position
- *
- * @return $seekPosition Current seek position
- * @throws UnsupportedOperationException If this method is called
- */
- public function determineSeekPosition () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Seek to given offset (default) or other possibilities as fseek() gives.
- *
- * @param $offset Offset to seek to (or used as "base" for other seeks)
- * @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of file seek: 0 = success, -1 = failed
- * @throws UnsupportedOperationException If this method is called
- */
- public function seek (int $offset, int $whence = SEEK_SET) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-ERROR-LOG-OUTPUT: offset=' . $offset . ',whence=' . $whence);
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- * @throws UnsupportedOperationException If this method is called
- */
- public function size () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
}
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
- /**
- * Determines seek position
- *
- * @return $seekPosition Current seek position
- * @throws UnsupportedOperationException If this method is called
- */
- public function determineSeekPosition () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Seek to given offset (default) or other possibilities as fseek() gives.
- *
- * @param $offset Offset to seek to (or used as "base" for other seeks)
- * @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of file seek: 0 = success, -1 = failed
- * @throws UnsupportedOperationException If this method is called
- */
- public function seek (int $offset, int $whence = SEEK_SET) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- * @throws UnsupportedOperationException If this method is called
- */
- public function size () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
}
// Import framework stuff
use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
-use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
use Org\Mxchange\CoreFramework\Output\BaseOutput;
use Org\Mxchange\CoreFramework\Registry\Registerable;
use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
/**
* Create a new web output system and set the content type
*
- * @param $applicationInstance An instance of a ManageableApplication class
- * @return $debugInstance An instance of this middleware class
+ * @return $webInstance An instance of an OutputStreamer class
*/
- public static final function createWebOutput (ManageableApplication $applicationInstance) {
+ public static final function createWebOutput () {
// Is the self-instance already set?
if (is_null(self::$webInstance)) {
// Get a new instance and set it
if (!empty($contentType)) {
// Set the header
FrameworkBootstrap::getResponseInstance()->addHeader('Content-type', $contentType);
- } // END - if
- } // END - if
+ }
+ }
// Return instance
return self::$webInstance;
print(stripslashes($outStream));
}
- /**
- * Determines seek position
- *
- * @return $seekPosition Current seek position
- * @throws UnsupportedOperationException If this method is called
- */
- public function determineSeekPosition () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Seek to given offset (default) or other possibilities as fseek() gives.
- *
- * @param $offset Offset to seek to (or used as "base" for other seeks)
- * @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of file seek: 0 = success, -1 = failed
- * @throws UnsupportedOperationException If this method is called
- */
- public function seek (int $offset, int $whence = SEEK_SET) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- * @throws UnsupportedOperationException If this method is called
- */
- public function size () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
}
* @throws UnexpectedValueException If header is not proper length
* @throws InvalidMagicException If a bad magic was found
*/
- public function readFileHeader () {
+ public function readStackHeader () {
// First rewind to beginning as the header sits at the beginning ...
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: CALLED!');
$this->getIteratorInstance()->rewind();
}
// Load the file header
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->readFileHeader() ...');
- $this->readFileHeader();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->readStackHeader() ...');
+ $this->readStackHeader();
/*
* Get stack index instance. This can be used for faster
$this->setIndexInstance($indexInstance);
// Is the index loaded correctly and the stack file is just created?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->indexInstance->isIndexFileLoaded() ...');
- if (!$this->getIndexInstance()->isIndexFileLoaded()) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calling this->indexInstance->isIndexLoaded() ...');
+ if (!$this->getIndexInstance()->isIndexLoaded()) {
/*
* Something horrible has happened to the index as it should be
* loaded at this point. The stack's file structure then needs to
/**
* Writes given value to the file and returns a hash and gap position for it
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $value Value to be added to the stack
* @return $data Hash and gap position
* @throws UnsupportedOperationException This method is not (and maybe never will be) supported
*/
- public function writeValueToFile (string $groupId, $value) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,value[%s]=%s', $groupId, gettype($value), print_r($value, true)));
+ public function writeValueToFile (string $stackName, $value) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,value[%s]=%s', $stackName, gettype($value), print_r($value, true)));
throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
}
/**
* Writes given raw data to the file and returns a gap position and length
*
- * @param $groupId Group identifier
+ * @param $stackName Group identifier
* @param $hash Hash from encoded value
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
*/
- public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
+ public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
// Raw data been written to the file
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,encoded()=%d - CALLED!', $groupId, $hash, strlen($encoded)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,encoded()=%d - CALLED!', $stackName, $hash, strlen($encoded)));
$rawData = sprintf('%s%s%s%s%s',
- $groupId,
+ $stackName,
BaseBinaryFile::SEPARATOR_GROUP_HASH,
hex2bin($hash),
BaseBinaryFile::SEPARATOR_HASH_VALUE,
);
// Search for next free gap
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,rawData()=%d', $groupId, $hash, strlen($rawData)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,rawData()=%d', $stackName, $hash, strlen($rawData)));
$gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
// Gap position cannot be smaller than header length + 1
}
// Then write the data at that gap
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,gapPosition=%s', $groupId, $hash, $gapPosition));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,gapPosition=%s', $stackName, $hash, $gapPosition));
$this->getIteratorInstance()->writeData($gapPosition, $rawData);
// Return gap position, hash and length of raw data
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $hash, strlen($rawData)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,rawData()=%d - EXIT!', $stackName, $hash, strlen($rawData)));
return [
self::ARRAY_NAME_GAP_POSITION => $gapPosition,
self::ARRAY_NAME_HASH => $hash,
// Import SPL stuff
use \InvalidArgumentException;
+use \OutOfBoundsException;
use \SplFileInfo;
/**
* @param $seekPosition Seek position in file
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of this operation
- * @throws InvalidArgumentException If a parameter is invalid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function seek (int $seekPosition, int $whence = SEEK_SET) {
// Validate parameter
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FIFO-FILE-STACK: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
if ($seekPosition < 0) {
// Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
}
// @TODO Unfinished method or invoke inner iterator's method?
*/
const SEPARATOR_GAP_LENGTH = 0x03;
+ /**
+ * Checks whether the index has been fully loaded (and parsed)
+ *
+ * @return $isLoaded Whether the index has been loaded
+ */
+ function isIndexLoaded ();
+
}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Index\Indexable;
+
+/**
+ * An interface for indexable file classes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface FileIndexer extends Indexable {
+ /**
+ * Adds given data's hash to the index file
+ *
+ * @param $stackName Name of stack to add hash
+ * @param $data Hash and gap position to be added to the index
+ * @return void
+ * @throws InvalidArgumentException If a parameter is not valid
+ */
+ function addHashedDataToIndex (string $stackName, array $data);
+
+ /**
+ * Searches for next suitable gap the given length of data can fit in
+ * including padding bytes.
+ *
+ * @param $length Length of raw data
+ * @return $seekPosition Found next gap's seek position
+ * @throws InvalidArgumentException If the parameter is not valid
+ */
+ function searchNextGap (int $length);
+
+ /**
+ * Writes at given position by seeking to it.
+ *
+ * @param $seekPosition Seek position in file
+ * @param $dataStream Data to be written
+ * @return mixed Number of writes bytes or false on error
+ * @throws InvalidArgumentException If a parameter is not valid
+ */
+ function writeAtPosition (int $seekPosition, string $dataStream);
+
+}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Index\File\Stack;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
+use Org\Mxchange\CoreFramework\Index\File\FileIndexer;
+
+/**
+ * An interface for Indexable stack classes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface IndexableStack extends FileIndexer {
+
+}
+++ /dev/null
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Index\Stack;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
-use Org\Mxchange\CoreFramework\Index\Indexable;
-
-/**
- * An interface for Indexable stack classes
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface IndexableStack extends Indexable, CalculatableBlock {
- /**
- * Adds given data's hash to the index file
- *
- * @param $stackName Name of stack to add hash
- * @param $data Hash and gap position to be added to the index
- * @return void
- * @throws InvalidArgumentException If a parameter is not valid
- */
- function addHashedDataToIndex (string $stackName, array $data);
-
- /**
- * Checks whether the index' file has been fully loaded (and parsed)
- *
- * @return $isLoaded Whether the index' file has been loaded
- */
- function isIndexFileLoaded ();
-
-}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface Streamable extends FrameworkInterface {
- /**
- * Determines seek position
- *
- * @return $seekPosition Current seek position
- */
- function determineSeekPosition ();
-
- /**
- * Seek to given offset (default) or other possibilities as fseek() gives.
- *
- * @param $offset Offset to seek to (or used as "base" for other seeks)
- * @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of file seek: 0 = success, -1 = failed
- */
- function seek (int $offset, int $whence = SEEK_SET);
-
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- */
- function size ();
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface StreamableInput extends Streamable {
+ /**
+ * Determines seek position
+ *
+ * @return $seekPosition Current seek position
+ */
+ function determineSeekPosition ();
+
+ /**
+ * Seek to given offset (default) or other possibilities as fseek() gives.
+ *
+ * @param $offset Offset to seek to (or used as "base" for other seeks)
+ * @param $whence Added to offset (default: only use offset to seek to)
+ * @return void
+ * @throws OutOfBoundsException If the position is not seekable
+ */
+ function seek (int $offset, int $whence = SEEK_SET);
+
+ /**
+ * Size of file stack
+ *
+ * @return $size Size (in bytes) of file
+ */
+ function size ();
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface SeekableWritableFileIterator extends SeekableIterator {
- /**
- * Seeks to given position
- *
- * @param $seekPosition Seek position in file
- * @return $status Status of this operation
- */
- function seek (int $seekPosition);
-
/**
* Size of file stack
*
function size ();
/**
- * Reads the file header
+ * Reads the stack's file header
*
* @return void
* @todo To hard assertions here, better rewrite them to exceptions
* @throws UnexpectedValueException If header is not proper length
* @throws InvalidMagicException If a bad magic was found
*/
- function readFileHeader ();
+ function readStackHeader ();
/**
* Flushes the file header
*
* @param $offset Offset to seek to (or used as "base" for other seeks)
* @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of file seek: 0 = success, -1 = failed
+ * @return void
*/
public function seek (int $offset, int $whence = SEEK_SET) {
$this->partialStub('offset=' . $offset . ',whence=' . $whence);
+++ /dev/null
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Traits\Index\Stack;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
-
-/**
- * A trait for indexable stacks
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-trait IndexableStackTrait {
- /**
- * An instance of an IndexableStack class
- */
- private $indexInstance = NULL;
-
- /**
- * Setter for IndexableStack instance
- *
- * @param $indexInstance An instance of an IndexableStack class
- * @return void
- */
- protected final function setIndexableStackInstance (IndexableStack $indexInstance) {
- $this->indexInstance = $indexInstance;
- }
-
- /**
- * Getter for IndexableStack instance
- *
- * @return $indexInstance An instance of an IndexableStack class
- */
- public final function getIndexableStackInstance () {
- return $this->indexInstance;
- }
-
-}