namespace Org\Mxchange\CoreFramework\Iterator\File;
// Import framework stuff
-use Org\Mxchange\CoreFramework\Filesystem\Block;
+use Org\Mxchange\CoreFramework\Filesystem\File\BinaryFile;
use Org\Mxchange\CoreFramework\Iterator\BaseIterator;
use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
+use Org\Mxchange\CoreFramework\Traits\File\BinaryFileTrait;
// Import SPL stuff
use \BadMethodCallException;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class FileIterator extends BaseIterator implements SeekableWritableFileIterator {
- /**
- * An instance of a Block class
- */
- private $blockInstance = NULL;
+ // Load traits
+ use BinaryFileTrait;
/**
* Protected constructor
/**
* Creates an instance of this class
*
- * @param $blockInstance An instance of a Block class
+ * @param $binaryFileInstance An instance of a BinaryFile class
* @return $iteratorInstance An instance of a Iterator class
*/
- public final static function createFileIterator (Block $blockInstance) {
+ public final static function createFileIterator (BinaryFile $binaryFileInstance) {
// Get new instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: blockInstance=%s - CALLED!', $blockInstance->__toString()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: binaryFileInstance=%s - CALLED!', $binaryFileInstance->__toString()));
$iteratorInstance = new FileIterator();
// Set the instance here
- $iteratorInstance->setBlockInstance($blockInstance);
+ $iteratorInstance->setBinaryFileInstance($binaryFileInstance);
// Return the prepared instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: iteratorInstance=%s - EXIT!', $iteratorInstance->__toString()));
return $iteratorInstance;
}
- /**
- * Setter for Block instance
- *
- * @param $blockInstance An instance of an Block class
- * @return void
- */
- protected final function setBlockInstance (Block $blockInstance) {
- $this->blockInstance = $blockInstance;
- }
-
- /**
- * Getter for Block instance
- *
- * @return $blockInstance An instance of an Block class
- */
- public final function getBlockInstance () {
- return $this->blockInstance;
- }
-
/**
* Gets currently read data
*
throw new BadMethodCallException('Current key cannot be valid, forgot to invoke valid()?');
}
- // Call block instance
- $current = $this->getBlockInstance()->current();
+ // Call file instance
+ $current = $this->getBinaryFileInstance()->current();
// Return it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: current[]=%s - EXIT!', gettype($current)));
throw new BadMethodCallException('Current key cannot be valid, forgot to invoke valid()?');
}
- // Get key from block instance
- $key = $this->getBlockInstance()->determineSeekPosition();
+ // Get key from file instance
+ $key = $this->getBinaryFileInstance()->determineSeekPosition();
// Return key
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: key[%s]=%s - EXIT!', gettype($key), $key));
}
/**
- * Advances to next "block" of bytes
+ * Advances to next "file" of bytes
*
* @return void
*/
public function next () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBlockInstance()->next();
+ $this->getBinaryFileInstance()->next();
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return $status Status of this operation
*/
public function rewind () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBlockInstance()->rewind();
+ $this->getBinaryFileInstance()->rewind();
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return $isValid Whether the next entry is valid
*/
public function valid () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $isValid = $this->getBlockInstance()->valid();
+ $isValid = $this->getBinaryFileInstance()->valid();
// Return flag
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isValid=%d - EXIT!', intval($isValid)));
throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
}
- // Call block instance
- $status = $this->getBlockInstance()->seek($seekPosition, $whence);
+ // Call file instance
+ $status = $this->getBinaryFileInstance()->seek($seekPosition, $whence);
// Return status
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status=%d - EXIT!', intval($status)));
* @return $size Size (in bytes) of file
*/
public function size () {
- // Call the block object
+ // Call the file object
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $size = $this->getBlockInstance()->size();
+ $size = $this->getBinaryFileInstance()->size();
// Return size
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
}
- // Call block instance
- $data = $this->getBlockInstance()->read($bytes);
+ // Call file instance
+ $data = $this->getBinaryFileInstance()->read($bytes);
// Return data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
* @return void
*/
public function analyzeFileStructure () {
- // Just call the block instance
+ // Just call the file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBlockInstance()->analyzeFileStructure();
+ $this->getBinaryFileInstance()->analyzeFileStructure();
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return $isInitialized Whether the file header is initialized
*/
public function isFileHeaderInitialized () {
- // Just call the block instance
+ // Just call the file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $isInitialized = $this->getBlockInstance()->isFileHeaderInitialized();
+ $isInitialized = $this->getBinaryFileInstance()->isFileHeaderInitialized();
// Return flag
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isInitialized=%d - EXIT!', intval($isInitialized)));
* @return void
*/
public function createFileHeader () {
- // Just call the block instance
+ // Just call the file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBlockInstance()->createFileHeader();
+ $this->getBinaryFileInstance()->createFileHeader();
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
throw new InvalidArgumentException('Parameter "type" is empty');
}
- // Just call the block instance
- $this->getBlockInstance()->preAllocateFile($type);
+ // Just call the file instance
+ $this->getBinaryFileInstance()->preAllocateFile($type);
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return void
*/
public function initCountersGapsArray () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBlockInstance()->initCountersGapsArray();
+ $this->getBinaryFileInstance()->initCountersGapsArray();
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return $totalEntries Size of file header
*/
public final function getHeaderSize () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $size = $this->getBlockInstance()->getHeaderSize();
+ $size = $this->getBinaryFileInstance()->getHeaderSize();
// Return size
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
* @return void
*/
public final function setHeaderSize (int $headerSize) {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: headerSize=%d - CALLED!', $headerSize));
- $this->getBlockInstance()->setHeaderSize($headerSize);
+ $this->getBinaryFileInstance()->setHeaderSize($headerSize);
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return $header Header array
*/
public final function getHeader () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $header = $this->getBlockInstance()->getHeader();
+ $header = $this->getBinaryFileInstance()->getHeader();
// Return it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - EXIT!', count($header)));
* @return void
*/
public final function setHeader (array $header) {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - CALLED!', count($header)));
- $this->getBlockInstance()->setHeader($header);
+ $this->getBinaryFileInstance()->setHeader($header);
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return void
*/
public function updateSeekPosition () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBlockInstance()->updateSeekPosition();
+ $this->getBinaryFileInstance()->updateSeekPosition();
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
* @return $totalEntries Total entries in this file
*/
public final function getCounter () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $counter = $this->getBlockInstance()->getCounter();
+ $counter = $this->getBinaryFileInstance()->getCounter();
// Return counter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: counter=%d - EXIT!', $counter));
* @return $fileSize Size of currently loaded file
*/
public function getFileSize () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $size = $this->getBlockInstance()->getFileSize();
+ $size = $this->getBinaryFileInstance()->getFileSize();
// Return size
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
throw new InvalidArgumentException('Parameter "data" is empty');
}
- // Call block instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->blockInstance->writeData(%d,data()=%d,%d) ...', $seekPosition, strlen($data), intval($flushHeader)));
- $this->getBlockInstance()->writeData($seekPosition, $data, $flushHeader);
+ // Call file instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->binaryFileInstance->writeData(%d,data()=%d,%d) ...', $seekPosition, strlen($data), intval($flushHeader)));
+ $this->getBinaryFileInstance()->writeData($seekPosition, $data, $flushHeader);
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
}
// Call iterated object's method
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->blockInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
- $status = $this->getBlockInstance()->writeAtPosition($seekPosition, $dataStream);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->binaryFileInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
+ $status = $this->getBinaryFileInstance()->writeAtPosition($seekPosition, $dataStream);
// Return status
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: status[%s]=%d - EXIT!', gettype($status), $status));
* @return $seekPosition Current seek position (stored here in object)
*/
public function getSeekPosition () {
- // Call block instance
+ // Call file instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $seekPosition = $this->getBlockInstance()->getSeekPosition();
+ $seekPosition = $this->getBinaryFileInstance()->getSeekPosition();
// Return position
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition));
throw new InvalidArgumentException(sprintf('value[]=%s is not supported by file-based indexes', gettype($value)));
}
- // Call block instance
- $data = $this->getBlockInstance()->writeValueToFile($groupId, $value);
+ // Call file instance
+ $data = $this->getBinaryFileInstance()->writeValueToFile($groupId, $value);
// Return data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
*/
public function writeDataToFreeGap (string $groupId, string $hash, string $encoded) {
// Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,hash=%s,encoded()=%d - CALLED!', $groupId, $hash, strlen($encoded)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: groupId=%s,hash=%s,encoded(%d)=%s - CALLED!', $groupId, $hash, strlen($encoded), $encoded));
- // Call block instance
- $data = $this->getBlockInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
+ // Call file instance
+ $data = $this->getBinaryFileInstance()->writeDataToFreeGap($groupId, $hash, $encoded);
// Return data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
}
- // Call block instance
- $seekPosition = $this->getBlockInstance()->searchNextGap($length);
+ // Call file instance
+ $seekPosition = $this->getBinaryFileInstance()->searchNextGap($length);
// Return position
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition));