From: Roland Haeder Date: Mon, 23 Jun 2014 21:15:24 +0000 (+0200) Subject: writeAtPosition() also belongs in OutputPointer classes. X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=767aecebb55bc8bb00f1688d7470868bd2c6d465 writeAtPosition() also belongs in OutputPointer classes. Signed-off-by: Roland Häder --- diff --git a/inc/classes/interfaces/io/pointer/class_OutputPointer.php b/inc/classes/interfaces/io/pointer/class_OutputPointer.php index 06c5835f..472bba55 100644 --- a/inc/classes/interfaces/io/pointer/class_OutputPointer.php +++ b/inc/classes/interfaces/io/pointer/class_OutputPointer.php @@ -33,6 +33,15 @@ interface OutputPointer extends StreamableOutput, Pointer { * an invalid file resource */ function writeToFile ($dataStream); + + /** + * Writes at given position by seeking to it. + * + * @param $seekPosition Seek position in file + * @param $data Data to be written + * @return mixed Number of writes bytes or FALSE on error + */ + function writeAtPosition ($seedPosition, $data); } // [EOF] diff --git a/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php b/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php index 3bb0d816..12df16c8 100644 --- a/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php +++ b/inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php @@ -38,15 +38,6 @@ interface SeekableWritableFileIterator extends SeekableIterator { */ function size (); - /** - * Writes at given position by seeking to it. - * - * @param $seekPosition Seek position in file - * @param $data Data to be written - * @return void - */ - function writeAtPosition ($seedPosition, $data); - /** * Reads given amount of bytes from file. * diff --git a/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php b/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php index fb1762ad..05d064d8 100644 --- a/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php +++ b/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php @@ -124,6 +124,21 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP return fwrite($this->getPointer(), $dataStream, strlen($dataStream)); } + /** + * Writes at given position by seeking to it. + * + * @param $seekPosition Seek position in file + * @param $data Data to be written + * @return mixed Number of writes bytes or FALSE on error + */ + public function writeAtPosition ($seekPosition, $data) { + // First seek to it + $this->seek($seekPosition); + + // Then write the data at that position + return $this->getBlockInstance()->writeToFile($data); + } + /** * Rewinds to the beginning of the file * diff --git a/inc/classes/main/index/class_BaseIndex.php b/inc/classes/main/index/class_BaseIndex.php index 9e001be7..b2977c68 100644 --- a/inc/classes/main/index/class_BaseIndex.php +++ b/inc/classes/main/index/class_BaseIndex.php @@ -122,7 +122,7 @@ class BaseIndex extends BaseFrameworkSystem { ); // Write it to disk (header is always at seek position 0) - $this->writeData(0, $header, FALSE); + $this->getIteratorInstance()->writeData(0, $header, FALSE); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); } diff --git a/inc/classes/main/iterator/file/class_FileIterator.php b/inc/classes/main/iterator/file/class_FileIterator.php index e7336074..f8fadbde 100644 --- a/inc/classes/main/iterator/file/class_FileIterator.php +++ b/inc/classes/main/iterator/file/class_FileIterator.php @@ -112,21 +112,6 @@ class FileIterator extends BaseIterator implements SeekableWritableFileIterator return $this->getBlockInstance()->seek($seekPosition); } - /** - * Writes at given position by seeking to it. - * - * @param $seekPosition Seek position in file - * @param $data Data to be written - * @return void - */ - public function writeAtPosition ($seekPosition, $data) { - // First seek to it - $this->seek($seekPosition); - - // Then write the data at that position - $this->getBlockInstance()->writeToFile($data); - } - /** * Size of file stack * diff --git a/inc/classes/main/stacker/file/class_BaseFileStack.php b/inc/classes/main/stacker/file/class_BaseFileStack.php index d225950b..8c518b4f 100644 --- a/inc/classes/main/stacker/file/class_BaseFileStack.php +++ b/inc/classes/main/stacker/file/class_BaseFileStack.php @@ -126,14 +126,14 @@ class BaseFileStack extends BaseStacker { chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), // Position (will be zero) - str_pad($this->dec2hex($this->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT), + str_pad($this->dec2hex($this->getIteratorInstance()->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT), // Separator position<->entries chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES) ); // Write it to disk (header is always at seek position 0) - $this->writeData(0, $header, FALSE); + $this->getIteratorInstance()->writeData(0, $header, FALSE); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__)); }