* @param $infoInstance An instance of a SplFileInfo class
* @return $indexInstance An instance of a IndexableStack class
*/
- public static final function createFileStackIndexInstance (SplFileInfo $infoInstance, $type) {
+ public static final function createFileStackIndexInstance (SplFileInfo $infoInstance, string $type) {
// If there is no handler?
if (GenericRegistry::getRegistry()->instanceExists($type . '_index')) {
// Get handler from registry
use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
// Import SPL stuff
+use \BadMethodCallException;
use \SplFileInfo;
/**
/* Only for debugging
if (isset($this->gaps[0])) {
// Output first and last gap
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] this->gaps[0]=%s,this->gaps[%s]=%s', __METHOD__, __LINE__, print_r($this->gaps[0], true), (count($this->gaps) - 1), print_r($this->gaps[count($this->gaps) - 1], true)));
- } // END - if
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] this->gaps[0]=%s,this->gaps[%s]=%s', print_r($this->gaps[0], true), (count($this->gaps) - 1), print_r($this->gaps[count($this->gaps) - 1], true)));
+ }
*/
// Now count every gap
foreach ($this->gaps as $gap) {
// Calculate size of found gap: end-start including both
$gapsSize += ($gap[self::GAPS_INDEX_END] - $gap[self::GAPS_INDEX_START]);
- } // END - if
+ }
// Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] gapsSize=%s,this->headerSize=%s', __METHOD__, __LINE__, $gapsSize, $this->getHeaderSize()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] gapsSize=%s,this->headerSize=%s', $gapsSize, $this->getHeaderSize()));
// Total gap size + header size must be same as file size
$isGapsOnly = (($this->getHeaderSize() + $gapsSize) == $this->getFileSize());
* @param $headerSize Size of file header
* @return void
*/
- public final function setHeaderSize ($headerSize) {
+ public final function setHeaderSize (int $headerSize) {
// Set it
$this->headerSize = $headerSize;
}
* @param $seekPosition Current seek position (stored here in object)
* @return void
*/
- protected final function setSeekPosition ($seekPosition) {
+ protected final function setSeekPosition (int $seekPosition) {
// And set it
$this->seekPosition = $seekPosition;
}
* @return void
*/
public function updateSeekPosition () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!'));
// Get key (= seek position)
$seekPosition = $this->key();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Setting seekPosition=%s', __METHOD__, __LINE__, $seekPosition));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Setting seekPosition=%s', $seekPosition));
// And set it here
$this->setSeekPosition($seekPosition);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!'));
}
/**
* @return void
*/
protected function rewindUpdateSeekPosition () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!'));
// flushFileHeader must be callable
assert(is_callable(array($this, 'flushFileHeader')));
// ... to write it back into the file
$this->flushFileHeader();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!'));
}
/**
* @return void
*/
protected function seekToOldPosition () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!'));
// Seek to currently ("old") saved position
$this->seek($this->getSeekPosition());
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!'));
}
/**
* @param $backBuffer Characters to "store" in back-buffer
* @return void
*/
- private function setBackBuffer ($backBuffer) {
- // Cast to string (so no arrays or objects)
- $backBuffer = (string) $backBuffer;
-
+ private function setBackBuffer (string $backBuffer) {
// ... and set it
$this->backBuffer = $backBuffer;
}
* @param $currentBlock Characters to set a currently loaded block
* @return void
*/
- private function setCurrentBlock ($currentBlock) {
- // Cast to string (so no arrays or objects)
- $currentBlock = (string) $currentBlock;
-
+ private function setCurrentBlock (string $currentBlock) {
// ... and set it
$this->currentBlock = $currentBlock;
}
*/
protected function initFile (SplFileInfo $infoInstance) {
// Get a file i/o pointer instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: infoInstance=%s - CALLED!', $infoInstance));
$pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($infoInstance));
// ... and set it here
$this->setPointerInstance($pointerInstance);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
/**
* @param $flushHeader Whether to flush the header (default: flush)
* @return void
*/
- public function writeData ($seekPosition, $data, $flushHeader = true) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data()=%d - CALLED!', __METHOD__, __LINE__, $seekPosition, strlen($data)));
-
+ public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
// Write data at given position
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader)));
$this->getPointerInstance()->writeAtPosition($seekPosition, $data);
// Increment counter
// Seek to old position
$this->seekToOldPosition();
- } // END - if
+ }
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
/**
* @param $length Length of the block
* @return void
*/
- protected function markCurrentBlockAsEmpty ($length) {
+ protected function markCurrentBlockAsEmpty (int $length) {
// Get current seek position
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length));
$currentPosition = $this->key();
// Now add it as gap entry
self::GAPS_INDEX_START => ($currentPosition - $length),
self::GAPS_INDEX_END => $currentPosition,
));
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
/**
* @return $isInitialized Whether the file header is initialized
*/
public function isFileHeaderInitialized () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
// Default is not initialized
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
$isInitialized = false;
// Is the file initialized?
if ($this->isFileInitialized()) {
// Some bytes has been written, so rewind to start of it.
$rewindStatus = $this->rewind();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] rewindStatus=%s', __METHOD__, __LINE__, $rewindStatus));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('rewindStatus=%s', $rewindStatus));
// Is the rewind() call successfull?
if ($rewindStatus != 1) {
// Something bad happened
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Could not rewind().', __METHOD__, __LINE__));
- } // END - if
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Could not rewind().'));
+ }
// Read file header
$this->readFileHeader();
// The above method does already check the header
$isInitialized = true;
- } // END - if
+ }
// Return result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] isInitialized=%d - EXIT!', __METHOD__, __LINE__, intval($isInitialized)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('isInitialized=%d - EXIT!', intval($isInitialized)));
return $isInitialized;
}
* @return $isInitialized Whether the file's size is zero
*/
public function isFileInitialized () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
// Get it from iterator which holds the pointer instance. If false is returned
$fileSize = $this->size();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] fileSize=%s', __METHOD__, __LINE__, $fileSize));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileSize=%s', $fileSize));
/*
* The returned file size should not be false or NULL as this means
$isInitialized = ($fileSize > 0);
// Return result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] isInitialized=%d - EXIT!', __METHOD__, __LINE__, intval($isInitialized)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('isInitialized=%d - EXIT!', intval($isInitialized)));
return $isInitialized;
}
* @return void
*/
public function createFileHeader () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
// The file's header should not be initialized here
assert(!$this->isFileHeaderInitialized());
// Rewind seek position (to beginning of file) and update/flush file header
$this->rewindUpdateSeekPosition();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
/**
* @param $type Type of the file
* @return void
*/
- public function preAllocateFile ($type) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
+ public function preAllocateFile (string $type) {
// Is it enabled?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
// Not enabled
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Not pre-allocating file.', __METHOD__, __LINE__));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Not pre-allocating file.'));
// Don't continue here.
return;
- } // END - if
+ }
// Message to user
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Pre-allocating file ...', __METHOD__, __LINE__));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Pre-allocating file ...'));
// Calculate minimum length for one entry
$minLengthEntry = $this->getBlockInstance()->calculateMinimumBlockLength();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] minLengthEntry=%s', __METHOD__, __LINE__, $minLengthEntry));
// Calulcate seek position
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('minLengthEntry=%s', $minLengthEntry));
$seekPosition = $minLengthEntry * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count');
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s', __METHOD__, __LINE__, $seekPosition));
// Now simply write a NUL there. This will pre-allocate the file.
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('seekPosition=%s', $seekPosition));
$this->writeData($seekPosition, chr(0));
// Rewind seek position (to beginning of file) and update/flush file header
$this->rewindUpdateSeekPosition();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
/**
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, $whence = SEEK_SET) {
// Call pointer instance
return $this->getPointerInstance()->seek($offset, $whence);
}
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- public function read ($bytes = NULL) {
- // $bytes shall be integer
- assert(is_int($bytes));
-
+ public function read (int $bytes = NULL) {
// Call pointer instance
return $this->getPointerInstance()->read($bytes);
}
* only gaps are found, the file is considered as "virgin" (no entries).
*
* @return void
+ * @throws BadMethodCallException If this method is called but file is not initialized
*/
public function analyzeFile () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
// Make sure the file is initialized
- assert($this->isFileInitialized());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
+ if (!$this->isFileInitialized()) {
+ // Bad method call
+ throw new BadMethodCallException('Method called but file is not initialized.');
+ }
// Init counters and gaps array
$this->initCountersGapsArray();
// Output message (as this may take some time)
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Analyzing file structure ... (this may take some time)', __METHOD__, __LINE__));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Analyzing file structure ... (this may take some time)'));
// First rewind to the begining
$this->rewind();
if (empty($current)) {
// Then skip this part
continue;
- } // END - if
+ }
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] current()=%d', __METHOD__, __LINE__, strlen($current)));
- } // END - while
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('current()=%d', strlen($current)));
+ }
// If the last read block is empty, check gaps
if (empty($current)) {
// Output message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Found a total of %s gaps.', __METHOD__, __LINE__, count($this->gaps)));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Found a total of %s gaps.', count($this->gaps)));
// Check gaps, if the whole file is empty.
if ($this->isFileOnlyGaps()) {
// Only gaps, so don't continue here.
return;
- } // END - if
+ }
/*
* The above call has calculated a total size of all gaps. If the
if ($this->isDefragmentationNeeded()) {
// Run "defragmentation"
$this->doRunDefragmentation();
- } // END - if
- } // END - if
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ }
+ }
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
/**
* Advances to next "block" of bytes
*
* @return void
+ * @throws UnexpectedValueException If some unexpected value was found
*/
public function next () {
// Is there nothing to read?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
if (!$this->valid()) {
// Nothing to read
return;
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d] key()=%d', __FUNCTION__, __LINE__, $this->key()));
-
- // Make sure the block instance is set
- assert($this->getBlockInstance() instanceof CalculatableBlock);
+ }
// First calculate minimum block length
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: key()=%d', $this->key()));
$length = $this->getBlockInstance()->calculateMinimumBlockLength();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d] length=%s', __FUNCTION__, __LINE__, $length));
-
- // Short be more than zero!
- assert($length > 0);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%s', $length));
// Read possibly back-buffered bytes from previous call of next().
$data = $this->getBackBuffer();
* "block" may not fit, so this loop will continue until the EOB or EOF
* has been reached whatever comes first.
*/
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data()=%d', strlen($data)));
while ((!$this->isEndOfFileReached()) && (!self::isBlockSeparatorFound($data))) {
// Then read the next possible block
$block = $this->read($length);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d] block()=%d,length=%s', __FUNCTION__, __LINE__, strlen($block), $length));
-
// Is it all empty?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: block()=%d,length=%s', strlen($block), $length));
if (strlen(trim($block)) == 0) {
// Mark this block as empty
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling markCurrentBlockAsEmpty(%d) ...', strlen($block)));
$this->markCurrentBlockAsEmpty(strlen($block));
// Skip to next block
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CONTINUE!');
continue;
- } // END - if
+ }
// At this block then
$data .= $block;
// A debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d] data()=%d', __FUNCTION__, __LINE__, strlen($data)));
- } // END - while
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: data()=%d', strlen($data)));
+ }
// EOF reached?
if ($this->isEndOfFileReached()) {
// Set whole data as current read block
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('Calling setCurrentBlock(' . strlen($data) . ') ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling setCurrentBlock(%d) ...', strlen($data)));
$this->setCurrentBlock($data);
// Then abort here silently
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('EOF reached.');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EOF reached - EXIT!');
return;
- } // END - if
+ }
/*
* Init back-buffer which is the data that has been found beyond the
$dataArray = explode(chr(self::SEPARATOR_ENTRIES), $data);
// This array must contain two elements
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('dataArray=' . print_r($dataArray, true));
- assert(count($dataArray) == 2);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: dataArray=' . print_r($dataArray, true));
+ if (count($dataArray) != 2) {
+ // Bad count
+ throw new UnexpectedValueException(sprintf('dataArray()=%d is not expected, want 2', count($dataArray)));
+ }
// Left part is the actual block, right one the back-buffer data
$this->setCurrentBlock($dataArray[0]);
$this->setBackBuffer($dataArray[1]);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
/**
* @return $isValid Whether the next entry is valid
*/
public function valid () {
- // Make sure the block instance is set
- assert($this->getBlockInstance() instanceof Block);
-
// First calculate minimum block length
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
$length = $this->getBlockInstance()->calculateMinimumBlockLength();
// Short be more than zero!
* @return void
*/
public function readFileHeader () {
- // Make sure the block instance is set
- assert($this->getBlockInstance() instanceof Block);
-
// Call block instance
$this->getBlockInstance()->readFileHeader();
}
* @return void
*/
public function flushFileHeader () {
- // Make sure the block instance is set
- assert($this->getBlockInstance() instanceof Block);
-
// Call block instance
$this->getBlockInstance()->flushFileHeader();
}
* @param $length Length of raw data
* @return $seekPosition Found next gap's seek position
*/
- public function searchNextGap ($length) {
+ public function searchNextGap (int $length) {
// If the file is only gaps, no need to seek
if ($this->isFileOnlyGaps()) {
// The first empty block is the first one right after the header
return ($this->getHeaderSize() + 1);
- } // END - if
+ }
// @TODO Unfinished
$this->partialStub('length=' . $length);
*/
public final static function createIndexFile (SplFileInfo $fileInfoInstance, Block $blockInstance) {
// Get a new instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance=%s,blockInstance=%s - CALLED!', $fileInfoInstance, $blockInstance->__toString()));
$fileInstance = new IndexFile();
// Set block instance here for callbacks
$fileInstance->setBlockInstance($blockInstance);
+ // Expand file name with .idx
+ $indexInfoInstance = new SplFileInfo(sprintf('%s.idx', $fileInfoInstance->__toString()));
+
// Init this abstract file
- $fileInstance->initFile($fileInfoInstance);
+ $fileInstance->initFile($indexInfoInstance);
// Return the prepared instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInstance=%s - EXIT!', $fileInstance->__toString()));
return $fileInstance;
}
* @return $data Hash and gap position
* @throws UnsupportedOperationException If this method is called
*/
- public function writeValueToFile ($groupId, $value) {
+ public function writeValueToFile (string $groupId, $value) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] groupId=' . $groupId . ',value[' . gettype($value) . ']=' . print_r($value, true));
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return $data Gap position and length of the raw data
* @throws UnsupportedOperationException If this method is called
*/
- public function writeDataToFreeGap ($groupId, $hash, $encoded) {
+ public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] groupId=' . $groupId . ',encoded()=' . strlen($encoded));
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return $data Gap position and length of the raw data
* @throws UnsupportedOperationException If this method is called
*/
- public function writeDataToFreeGap ($groupId, $hash, $encoded) {
+ public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] groupId=' . $groupId . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
// Import SPL stuff
use \SplFileInfo;
+use \UnexpectedValueException;
/**
* A general index class
* Reads the file header
*
* @return void
+ * @throws UnexpectedValueException If header length is invalid
*/
public function readFileHeader () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
// 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());
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Read %d bytes (%d wanted).', __METHOD__, __LINE__, strlen($data), $this->getIteratorInstance()->getHeaderSize()));
// Have all requested bytes been read?
- assert(strlen($data) == $this->getIteratorInstance()->getHeaderSize());
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
-
- // Last character must be the separator
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data(-1)=%s', __METHOD__, __LINE__, dechex(ord(substr($data, -1, 1)))));
- assert(substr($data, -1, 1) == chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES));
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('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 (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);
$this->getIteratorInstance()->setHeader($header);
// Check if the array has only 3 elements
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] header(%d)=%s', __METHOD__, __LINE__, count($header), print_r($header, true)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('header(%d)=%s', count($header), print_r($header, true)));
assert(count($header) == 2);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
// Check magic
assert($header[0] == self::INDEX_MAGIC);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
// Check length of count
assert(strlen($header[1]) == BaseBinaryFile::LENGTH_COUNT);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
// Decode count
$header[1] = hex2bin($header[1]);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
}
/**
* @return void
*/
public function flushFileHeader () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
-
// Put all informations together
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
$header = sprintf('%s%s%s%s',
// Magic
self::INDEX_MAGIC,
// Write it to disk (header is always at seek position 0)
$this->getIteratorInstance()->writeData(0, $header, false);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
}
/**
*/
protected function initIndex (SplFileInfo $fileInfoInstance) {
// Get a file i/o pointer instance for index file
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileInfoInstance=%s - CALLED!', $fileInfoInstance));
$fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
// Get iterator instance
$iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance));
- // Is the instance implementing the right interface?
- assert($iteratorInstance instanceof SeekableWritableFileIterator);
-
// Set iterator here
$this->setIteratorInstance($iteratorInstance);
// And pre-allocate a bit
$this->getIteratorInstance()->preAllocateFile('index');
- } // END - if
+ }
// Load the file header
$this->readFileHeader();
// Count all entries in file
$this->getIteratorInstance()->analyzeFile();
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: EXIT!');
}
/**
*/
public function calculateMinimumBlockLength () {
// Calulcate it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
$length = BaseBinaryFile::LENGTH_TYPE + strlen(chr(BaseBinaryFile::SEPARATOR_TYPE_POSITION)) + BaseBinaryFile::LENGTH_POSITION + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES));
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-INDEX: length=%d - EXIT!', $length));
return $length;
}
* @return void
* @throws UnsupportedOperationException This method is not (and maybe never will be) supported
*/
- public final function setHeaderSize ($headerSize) {
+ public final function setHeaderSize (int $headerSize) {
throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return void
* @throws UnsupportedOperationException This method is not (and maybe never will be) supported
*/
- public function writeData ($seekPosition, $data, $flushHeader = true) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data[]=%s,flushHeader=%d', __METHOD__, __LINE__, $seekPosition, gettype($data), intval($flushHeader)));
+ 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);
}
* @return $data Hash and gap position
* @throws UnsupportedOperationException If this method is called
*/
- public function writeValueToFile ($groupId, $value) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] groupId=' . $groupId . ',value[' . gettype($value) . ']=' . print_r($value, true));
+ 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);
}
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
*/
- public function writeDataToFreeGap ($groupId, $hash, $encoded) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] groupId=' . $groupId . ',hash=' . $hash . ',encoded()=' . strlen($encoded));
+ 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);
}
*/
public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
// Get a new instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance=%s - CALLED!', $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;
}
* @param $data Hash and gap position to be added to the index
* @return void
*/
- public function addHashToIndex ($groupId, array $data) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,gap=%d,length=%d - CALLED!', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $data[BaseFileStack::ARRAY_INDEX_GAP_POSITION], $data[BaseFileStack::ARRAY_INDEX_DATA_LENGTH]));
-
+ public function addHashToIndex (string $groupId, array $data) {
// Raw data been written to the file
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gap=%d,length=%d - CALLED!', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $data[BaseFileStack::ARRAY_INDEX_GAP_POSITION], $data[BaseFileStack::ARRAY_INDEX_DATA_LENGTH]));
$rawData = sprintf('%s%s%s%s%s%s%s',
$groupId,
self::SEPARATOR_GROUP_HASH,
);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,rawData()=%d', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
// Search for next free gap
$gapPosition = $this->getIteratorInstance()->searchNextGap(strlen($rawData));
// Gap position cannot be smaller than header length + 1
assert($gapPosition > $this->getIteratorInstance()->getHeaderSize());
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,gapPosition=%s', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $gapPosition));
-
// Then write the data at that gap
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,gapPosition=%s', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], $gapPosition));
$this->getIteratorInstance()->writeData($gapPosition, $rawData);
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] groupId=%s,hash=%s,rawData()=%d - EXIT!', __METHOD__, __LINE__, $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $data[BaseFileStack::ARRAY_INDEX_HASH], strlen($rawData)));
}
/**
* @param $length Length of raw data
* @return $seekPosition Found next gap's seek position
*/
- public function searchNextGap ($length) {
+ public function searchNextGap (int $length) {
$this->partialStub('length=' . $length);
}
* @param $seekPosition Seek position in file
* @return $status Status of this operation
*/
- public function seek ($seekPosition) {
+ public function seek (int $seekPosition) {
// Call block instance
return $this->getBlockInstance()->seek($seekPosition);
}
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- public function read ($bytes = NULL) {
+ public function read (int $bytes = NULL) {
// Call block instance
return $this->getBlockInstance()->read($bytes);
}
* @param $type Type of the file
* @return void
*/
- public function preAllocateFile ($type) {
+ public function preAllocateFile (string $type) {
// Just call the block instance
$this->getBlockInstance()->preAllocateFile($type);
}
* @param $headerSize Size of file header
* @return void
*/
- public final function setHeaderSize ($headerSize) {
+ public final function setHeaderSize (int $headerSize) {
// Call block instance
$this->getBlockInstance()->setHeaderSize($headerSize);
}
* @param $flushHeader Whether to flush the header (default: flush)
* @return void
*/
- public function writeData ($seekPosition, $data, $flushHeader = true) {
+ public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
// Call block instance
$this->getBlockInstance()->writeData($seekPosition, $data, $flushHeader);
}
* @param $value Value to be added to the stack
* @return $data Hash and gap position
*/
- public function writeValueToFile ($groupId, $value) {
+ public function writeValueToFile (string $groupId, $value) {
// Call block instance
return $this->getBlockInstance()->writeValueToFile($groupId, $value);
}
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
*/
- public function writeDataToFreeGap ($groupId, $hash, $encoded) {
+ public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
// Call block instance
return $this->getBlockInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
}
* @param $length Length of raw data
* @return $seekPosition Found next gap's seek position
*/
- public function searchNextGap ($length) {
+ public function searchNextGap (int $length) {
// Call block instance
print $this->getBlockInstance()->__toString() . PHP_EOL;
return $this->getBlockInstance()->searchNextGap($length);
*/
protected function initFileStack (SplFileInfo $fileInfoInstance, string $type) {
// Get a stack file instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance=%s,type=%s - CALLED!', $fileInfoInstance, $type));
$fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileInfoInstance, $this));
// Get iterator instance
$iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance));
- // Is the instance implementing the right interface?
- assert($iteratorInstance instanceof SeekableWritableFileIterator);
-
// Set iterator here
$this->setIteratorInstance($iteratorInstance);
// And pre-allocate a bit
$this->getIteratorInstance()->preAllocateFile('file_stack');
- } // END - if
+ }
// Load the file header
$this->readFileHeader();
* @param $value Value to add to this stacker
* @return void
* @throws FullStackerException If the stack is full
+ * @throws InvalidArgumentException Not all variable types are wanted here
*/
protected function addValue (string $stackerName, $value) {
// Do some tests
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('stackerName=%s,value[%s]=%s - CALLED!', $stackerName, gettype($value), print_r($value, true)));
if ($this->isStackFull($stackerName)) {
// Stacker is full
throw new FullStackerException(array($this, $stackerName, $value), self::EXCEPTION_STACKER_IS_FULL);
- } // END - if
-
- // No objects/resources are allowed as their serialization takes to long
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] stackerName=' . $stackerName . ',value[' . gettype($value) . ']=' . print_r($value, true));
- assert(!is_object($value));
- assert(!is_resource($value));
+ } elseif (is_resource($value) || is_object($value)) {
+ // Not wanted type
+ throw new InvalidArgumentException(sprintf('value[]=%s is not supported', gettype($value)));
+ }
/*
* Now add the value to the file stack which returns gap position, a
* @return void
* @throws UnsupportedOperationException This method is not (and maybe never will be) supported
*/
- public function writeData ($seekPosition, $data, bool $flushHeader = true) {
+ public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: seekPosition=%s,data[]=%s,flushHeader=%d', $seekPosition, gettype($data), intval($flushHeader)));
throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return $data Hash and gap position
* @throws UnsupportedOperationException This method is not (and maybe never will be) supported
*/
- public function writeValueToFile ($groupId, $value) {
+ 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)));
throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
*/
- public function writeDataToFreeGap ($groupId, string $hash, $encoded) {
+ public function writeDataToFreeGap (string $groupId, 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)));
$rawData = sprintf('%s%s%s%s%s',
* @param $value Value to be added to the stack
* @return $data Hash and gap position
*/
- function writeValueToFile ($groupId, $rawData);
+ function writeValueToFile (string $groupId, string $rawData);
/**
* Writes given raw data to the file and returns a gap position and length
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
*/
- function writeDataToFreeGap ($groupId, string $hash, $encoded);
+ function writeDataToFreeGap (string $groupId, string $hash, string $encoded);
/**
* Writes data at given position
* @param $flushHeader Whether to flush the header (default: flush)
* @return void
*/
- function writeData ($seekPosition, $data, bool $flushHeader = true);
+ function writeData (int $seekPosition, string $data, bool $flushHeader = true);
/**
* Searches for next suitable gap the given length of data can fit in
* @param $data Hash and gap position to be added to the index
* @return void
*/
- function addHashToIndex ($stackName, array $data);
+ function addHashToIndex (string $stackName, array $data);
}
* @param $seekPosition Seek position in file
* @return $status Status of this operation
*/
- function seek ($seekPosition);
+ function seek (int $seekPosition);
/**
* Size of file stack
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- function read ($bytes);
+ function read (int $bytes);
/**
* Analyzes entries in index file. This will count all found (and valid)
* @param $type Type of the file
* @return void
*/
- function preAllocateFile ($type);
+ function preAllocateFile (string $type);
/**
* Initializes counter for valid entries, arrays for damaged entries and
* @param $flushHeader Whether to flush the header (default: flush)
* @return void
*/
- function writeData ($seekPosition, $data, bool $flushHeader = true);
+ function writeData (int $seekPosition, string $data, bool $flushHeader = true);
/**
* Getter for seek position
* @param $value Value to be added to the stack
* @return $data Hash and gap position
*/
- function writeValueToFile ($groupId, $value);
+ function writeValueToFile (string $groupId, $value);
/**
* Writes given raw data to the file and returns a gap position and length
* @param $encoded Encoded value to be written to the file
* @return $data Gap position and length of the raw data
*/
- function writeDataToFreeGap ($groupId, string $hash, $encoded);
+ function writeDataToFreeGap (string $groupId, string $hash, string $encoded);
/**
* Searches for next suitable gap the given length of data can fit in