X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fiterator%2Ffile%2Fclass_FileIterator.php;h=0163ffed79afa326e269fa4a0fa3d4dc65575f1d;hb=024347bb5d62151f49c959cdeeaecc061fb2be66;hp=2442fb55fa1093a68102df2dd11a2bd8b3fcd90f;hpb=64adf2e0b8dc0f38717df467fe7a64c2ed39f32c;p=core.git diff --git a/framework/main/classes/iterator/file/class_FileIterator.php b/framework/main/classes/iterator/file/class_FileIterator.php index 2442fb55..0163ffed 100644 --- a/framework/main/classes/iterator/file/class_FileIterator.php +++ b/framework/main/classes/iterator/file/class_FileIterator.php @@ -3,9 +3,10 @@ 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; @@ -34,10 +35,8 @@ use \InvalidArgumentException; * along with this program. If not, see . */ class FileIterator extends BaseIterator implements SeekableWritableFileIterator { - /** - * An instance of a Block class - */ - private $blockInstance = NULL; + // Load traits + use BinaryFileTrait; /** * Protected constructor @@ -52,41 +51,22 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator /** * 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 * @@ -101,8 +81,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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))); @@ -123,8 +103,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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)); @@ -132,14 +112,14 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator } /** - * 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!'); @@ -151,9 +131,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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!'); @@ -166,9 +146,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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))); @@ -191,8 +171,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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))); @@ -205,9 +185,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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)); @@ -228,8 +208,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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))); @@ -244,9 +224,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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!'); @@ -258,9 +238,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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))); @@ -273,9 +253,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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!'); @@ -296,8 +276,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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!'); @@ -312,9 +292,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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!'); @@ -326,9 +306,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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)); @@ -342,9 +322,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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!'); @@ -356,9 +336,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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))); @@ -372,9 +352,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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!'); @@ -386,9 +366,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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!'); @@ -400,9 +380,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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)); @@ -415,9 +395,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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)); @@ -444,9 +424,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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!'); @@ -472,8 +452,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator } // 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)); @@ -486,9 +466,9 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator * @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)); @@ -514,8 +494,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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))); @@ -532,10 +512,10 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator */ 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))); @@ -558,8 +538,8 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator 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));