X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fiterator%2Fio%2Fclass_FileIoIterator.php;h=12cf82ea461e8f32fc5e3f32e4b11b6627dbf57a;hp=3437d1165902af54a1cc557527ec90cdd924844a;hb=5ffe42efd591f1d84d65a93b2965cdf6931f9442;hpb=a863937b246c06e143d147fe4108543056971472 diff --git a/inc/classes/main/iterator/io/class_FileIoIterator.php b/inc/classes/main/iterator/io/class_FileIoIterator.php index 3437d116..12cf82ea 100644 --- a/inc/classes/main/iterator/io/class_FileIoIterator.php +++ b/inc/classes/main/iterator/io/class_FileIoIterator.php @@ -36,15 +36,19 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato * Creates an instance of this class * * @param $pointerInstance An instance of a InputOutputPointer class + * @param $blockInstance An instance of a CalculatableBlock class * @return $iteratorInstance An instance of a Iterator class */ - public final static function createFileIoIterator (InputOutputPointer $pointerInstance) { + public final static function createFileIoIterator (InputOutputPointer $pointerInstance, CalculatableBlock $blockInstance) { // Get new instance $iteratorInstance = new FileIoIterator(); // Set the instance here $iteratorInstance->setPointerInstance($pointerInstance); + // Set the block instance here + $iteratorInstance->setBlockInstance($blockInstance); + // Return the prepared instance return $iteratorInstance; } @@ -97,10 +101,29 @@ class FileIoIterator extends BaseIterator implements SeekableWritableFileIterato * Checks wether the current entry is valid (not at the end of the file). * This method will return TRUE if an emptied (nulled) entry has been found. * - * @return void + * @return $isValid Whether the next entry is valid */ public function valid () { - $this->partialStub('Please implement this method.'); + // First calculate minimum block length + $length = $this->getBlockInstance()->caluclateMinimumBlockLength(); + + // Short be more than zero! + assert($length > 0); + + // Get current seek position + $seekPosition = $this->key(); + + // Then try to read it + $data = $this->read($length); + + // If some bytes could be read, all is fine + $isValid = ((is_string($data)) && (strlen($data) > 0)); + + // Seek back to old position + $this->seek($seekPosition); + + // Return result + return $isValid; } /**