writeAtPosition() also belongs in OutputPointer classes.
authorRoland Haeder <roland@mxchange.org>
Mon, 23 Jun 2014 21:15:24 +0000 (23:15 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 23 Jun 2014 21:15:24 +0000 (23:15 +0200)
Signed-off-by: Roland H├Ąder <roland@mxchange.org>
inc/classes/interfaces/io/pointer/class_OutputPointer.php
inc/classes/interfaces/iterator/class_SeekableWritableFileIterator.php
inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php
inc/classes/main/index/class_BaseIndex.php
inc/classes/main/iterator/file/class_FileIterator.php
inc/classes/main/stacker/file/class_BaseFileStack.php

index 06c5835..472bba5 100644 (file)
@@ -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]
index 3bb0d81..12df16c 100644 (file)
@@ -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.
         *
index fb1762a..05d064d 100644 (file)
@@ -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
         *
index 9e001be..b2977c6 100644 (file)
@@ -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__));
        }
index e733607..f8fadbd 100644 (file)
@@ -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
         *
index d225950..8c518b4 100644 (file)
@@ -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__));
        }