// Left part is the actual block, right one the back-buffer data, if found
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray()=%d', count($dataArray)));
- //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true)));
+ /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: dataArray=%s', print_r($dataArray, true)));
$this->setCurrentBlock($dataArray[0]);
// Is back buffere data found?
- if (!empty(trim($dataArray[1], chr(0)))) {
+ if (isset($dataArray[1]) && !empty(trim($dataArray[1], chr(0)))) {
// Set back buffer
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting this->backBuffer=%s ...', $dataArray[1]));
$this->setBackBuffer($dataArray[1]);
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
-use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
$this->getIteratorInstance()->rewind();
+ // Get header size
+ $headerSize = $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize();
+
// Then read it (see constructor for calculation)
- $data = $this->getIteratorInstance()->read($this->getIteratorInstance()->getHeaderSize());
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: headerSize=%d', $headerSize));
+ $data = $this->getIteratorInstance()->getBinaryFileInstance()->read($headerSize);
// Have all requested bytes been read?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getHeaderSize()));
- if (strlen($data) != $this->getIteratorInstance()->getHeaderSize()) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Read %d bytes (%d wanted).', strlen($data), $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()));
+ if (strlen($data) != $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()) {
// Invalid header length
throw new UnexpectedValueException(sprintf('data(%d)=%s is not expected length %d',
strlen($data),
$data,
- $this->getIteratorInstance()->getHeaderSize()
+ $this->getIteratorInstance()->getBinaryFileInstance()->getHeaderSize()
));
} elseif (empty(trim($data, chr(0)))) {
// Empty file header
// And update seek position
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->updateSeekPosition() ...');
- $this->getIteratorInstance()->updateSeekPosition();
+ $this->getIteratorInstance()->getBinaryFileInstance()->updateSeekPosition();
/*
* Now split it:
$header[1] = hex2bin($header[1]);
// Set it here
- $this->getIteratorInstance()->setHeader($header);
+ $this->getIteratorInstance()->getBinaryFileInstance()->setHeader($header);
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
// Total entries
- str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
+ str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
// Separator header<->entries
chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
// Write it to disk (header is always at seek position 0)
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Calling this->iteratorInstance->writeAtPosition(0, header=%s) ...', $header));
- $this->getIteratorInstance()->writeAtPosition(0, $header);
+ $this->getIteratorInstance()->getBinaryFileInstance()->writeAtPosition(0, $header);
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: EXIT!');
}
/**
- * Initializes this index
+ * Initializes this file-based index
*
* @param $fileInfoInstance An instance of a SplFileInfo class
* @return void
* @todo Currently the index file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole index file.
*/
- protected function initIndex (SplFileInfo $fileInfoInstance) {
+ protected function initFileIndex (SplFileInfo $fileInfoInstance) {
// Get a file i/o pointer instance for index file
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
$fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
// Set it
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Setting headerSize=%d ...', $headerSize));
- $this->getIteratorInstance()->setHeaderSize($headerSize);
+ $this->getIteratorInstance()->getBinaryFileInstance()->setHeaderSize($headerSize);
// Init counters and gaps array
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->initCountersGapsArray() ...');
- $this->getIteratorInstance()->initCountersGapsArray();
+ $this->getIteratorInstance()->getBinaryFileInstance()->initCountersGapsArray();
// Default is not created
$created = false;
// Is the file's header initialized?
- if (!$this->getIteratorInstance()->isFileHeaderInitialized()) {
+ if (!$this->getIteratorInstance()->getBinaryFileInstance()->isFileHeaderInitialized()) {
// First pre-allocate a bit
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->preAllocateFile(index) ...');
- $this->getIteratorInstance()->preAllocateFile('index');
+ $this->getIteratorInstance()->getBinaryFileInstance()->preAllocateFile('index');
// Then write file header
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->createFileHeader() ...');
- $this->getIteratorInstance()->createFileHeader();
+ $this->getIteratorInstance()->getBinaryFileInstance()->createFileHeader();
// Mark as freshly created
$created = true;
if (!$created) {
// Analyze file structure
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Calling this->iteratorInstance->analyzeFileStructure() ...');
- $this->getIteratorInstance()->analyzeFileStructure();
+ $this->getIteratorInstance()->getBinaryFileInstance()->analyzeFileStructure();
}
// Trace message
*/
public function getFileSize () {
// Call iterator's method
- return $this->getIteratorInstance()->getFileSize();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+ $fileSize = $this->getIteratorInstance()->getBinaryFileInstance()->getFileSize();
+
+ // Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: fileSize=%d - EXIT!', $fileSize));
+ return $fileSize;
}
/**
throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
}
- // Partial stub!
- $this->partialStub('length=' . $length);
+ // Debug message
+ /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: length=%d,this=%s', __METHOD__, __LINE__, $length, print_r($this, true)));
}
/**
// Call iterated object's method
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: Calling this->iteratorInstance->writeAtPosition(%d, %s) ...', $seekPosition, $dataStream));
- $status = $this->getIteratorInstance()->writeAtPosition($seekPosition, $dataStream);
+ $status = $this->getIteratorInstance()->getBinaryFileInstance()->writeAtPosition($seekPosition, $dataStream);
// Return status
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-INDEX: status[%s]=%d - EXIT!', gettype($status), $status));
*/
public function isIndexLoaded () {
// Is the file gaps-only?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: CALLED!');
- if ($this->getIteratorInstance()->isFileGapsOnly()) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: CALLED!');
+ if ($this->getIteratorInstance()->getBinaryFileInstance()->isFileGapsOnly()) {
// Then skip below code as this implies the file has been fully analyzed and "loaded"
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-INDEX: Underlaying file is gaps-only: Returning TRUE ... - EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-INDEX: Underlaying file is gaps-only: Returning TRUE ... - EXIT!');
return TRUE;
}
$indexInstance = new FileStackIndex();
// Initialize index
- $indexInstance->initIndex($fileInfoInstance);
+ $indexInstance->initFileIndex($fileInfoInstance);
// Return the prepared instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: indexInstance=%s - EXIT!', $indexInstance->__toString()));
// Import framework stuff
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;
use \InvalidArgumentException;
use \OutOfBoundsException;
+use \SeekableIterator;
/**
* A file iterator
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class FileIterator extends BaseIterator implements SeekableWritableFileIterator {
+class FileIterator extends BaseIterator implements SeekableIterator {
// Load traits
use BinaryFileTrait;
* Seeks to given position
*
* @param $seekPosition Seek position in file
- * @param $whence Added to offset (default: only use offset to seek to)
- * @return $status Status of this operation
+ * @return void
* @throws OutOfBoundsException If the position is not seekable
*/
- public function seek (int $seekPosition, int $whence = SEEK_SET) {
+ public function seek (int $seekPosition) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
if ($seekPosition < 0) {
}
// 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 $status;
- }
-
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- */
- public function size () {
- // Call the file object
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $size = $this->getBinaryFileInstance()->size();
-
- // Return size
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
- return $size;
- }
-
- /**
- * Reads given amount of bytes from file.
- *
- * @param $bytes Amount of bytes to read
- * @return $data Data read from file
- * @throws OutOfBoundsException If the position is not seekable
- */
- public function read (int $bytes = 0) {
- // Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: bytes=%d - CALLED!', $bytes));
- if ($bytes < 0) {
- // Throw exception
- throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $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 $data;
- }
-
- /**
- * Analyzes entries in index file. This will count all found (and valid)
- * entries, mark invalid as damaged and count gaps ("fragmentation"). If
- * only gaps are found, the file is considered as "virgin" (no entries).
- *
- * @return void
- */
- public function analyzeFileStructure () {
- // Just call the file instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBinaryFileInstance()->analyzeFileStructure();
-
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
- }
-
- /**
- * Checks whether the file header is initialized
- *
- * @return $isInitialized Whether the file header is initialized
- */
- public function isFileHeaderInitialized () {
- // Just call the file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $isInitialized = $this->getBinaryFileInstance()->isFileHeaderInitialized();
-
- // Return flag
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isInitialized=%d - EXIT!', intval($isInitialized)));
- return $isInitialized;
- }
-
- /**
- * Creates the assigned file
- *
- * @return void
- */
- public function createFileHeader () {
- // Just call the file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBinaryFileInstance()->createFileHeader();
-
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
- }
-
- /**
- * Pre-allocates file (if enabled) with some space for later faster write access.
- *
- * @param $type Type of the file
- * @return void
- * @throws InvalidArgumentException If a parameter is not valid
- */
- public function preAllocateFile (string $type) {
- // Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: type=%s - CALLED!', $type));
- if (empty($type)) {
- // Throw IAE
- throw new InvalidArgumentException('Parameter "type" is empty');
- }
-
- // Just call the file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: Calling this->binaryFileInstance->preAllocateFile(%s) ...', $type));
- $this->getBinaryFileInstance()->preAllocateFile($type);
-
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
- }
-
- /**
- * Initializes counter for valid entries, arrays for damaged entries and
- * an array for gap seek positions. If you call this method on your own,
- * please re-analyze the file structure. So you are better to call
- * analyzeFileStructure() instead of this method.
- *
- * @return void
- */
- public function initCountersGapsArray () {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBinaryFileInstance()->initCountersGapsArray();
-
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
- }
-
- /**
- * Getter for header size
- *
- * @return $totalEntries Size of file header
- */
- public final function getHeaderSize () {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $size = $this->getBinaryFileInstance()->getHeaderSize();
-
- // Return size
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
- return $size;
- }
-
- /**
- * Setter for header size
- *
- * @param $headerSize Size of file header
- * @return void
- */
- public final function setHeaderSize (int $headerSize) {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: headerSize=%d - CALLED!', $headerSize));
- $this->getBinaryFileInstance()->setHeaderSize($headerSize);
-
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
- }
-
- /**
- * Getter for header array
- *
- * @return $header Header array
- */
- public final function getHeader () {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $header = $this->getBinaryFileInstance()->getHeader();
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - EXIT!', count($header)));
- return $header;
- }
-
- /**
- * Setter for header
- *
- * @param $header Array for a file header
- * @return void
- */
- public final function setHeader (array $header) {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: header()=%d - CALLED!', count($header)));
- $this->getBinaryFileInstance()->setHeader($header);
-
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
- }
-
- /**
- * Updates seekPosition attribute from file to avoid to much access on file.
- *
- * @return void
- */
- public function updateSeekPosition () {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $this->getBinaryFileInstance()->updateSeekPosition();
-
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
- }
-
- /**
- * Getter for total entries
- *
- * @return $totalEntries Total entries in this file
- */
- public final function getCounter () {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $counter = $this->getBinaryFileInstance()->getCounter();
-
- // Return counter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: counter=%d - EXIT!', $counter));
- return $counter;
- }
-
- /**
- * "Getter" for file size
- *
- * @return $fileSize Size of currently loaded file
- */
- public function getFileSize () {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $size = $this->getBinaryFileInstance()->getFileSize();
-
- // Return size
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: size=%d - EXIT!', $size));
- return $size;
- }
-
- /**
- * Writes data at given position
- *
- * @param $seekPosition Seek position
- * @param $data Data to be written
- * @param $flushHeader Whether to flush the header (default: flush)
- * @return void
- * @throws OutOfBoundsException If the position is not seekable
- * @throws InvalidArgumentException If a parameter is not valid
- */
- public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
- // Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,data(%d)=%s,flushHeader=%d - CALLED!', $seekPosition, strlen($data), $data, intval($flushHeader)));
- if ($seekPosition < 0) {
- // Throw exception
- throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
- } elseif (empty($data)) {
- // Throw IAE
- throw new InvalidArgumentException('Parameter "data" is empty');
- }
-
- // 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);
+ $this->getBinaryFileInstance()->seek($seekPosition);
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: EXIT!');
}
- /**
- * Writes at given position by seeking to it.
- *
- * @param $seekPosition Seek position in file
- * @param $dataStream Data to be written
- * @return mixed Number of writes bytes or false on error
- * @throws OutOfBoundsException If the position is not seekable
- * @throws InvalidArgumentException If a parameter is not valid
- */
- public function writeAtPosition (int $seekPosition, string $dataStream) {
- // Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
- if ($seekPosition < 0) {
- // Invalid seek position
- throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
- } elseif (empty($dataStream)) {
- // Empty dataStream
- throw new InvalidArgumentException('Parameter "dataStream" is empty');
- }
-
- // Call iterated object's method
- //* 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 $status;
- }
-
- /**
- * Getter for seek position
- *
- * @return $seekPosition Current seek position (stored here in object)
- */
- public function getSeekPosition () {
- // Call file instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $seekPosition = $this->getBinaryFileInstance()->getSeekPosition();
-
- // Return position
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: seekPosition[%s]=%d - EXIT!', gettype($seekPosition), $seekPosition));
- return $seekPosition;
- }
-
- /**
- * Writes given value to the file and returns a hash and gap position for it
- *
- * @param $stackName Group identifier
- * @param $value Value to be added to the stack
- * @return $data Hash and gap position
- * @throws InvalidArgumentException If a parameter is not valid
- */
- public function writeValueToFile (string $stackName, $value) {
- // Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,value[]=%s - CALLED!', $stackName, gettype($value)));
- if (empty($stackName)) {
- // Throw IAE
- throw new InvalidArgumentException('Parameter "stackName" is empty');
- } elseif (is_resource($value) || is_object($value)) {
- // Resources and objects are nothing for file-based indexes (mostly)
- throw new InvalidArgumentException(sprintf('value[]=%s is not supported by file-based indexes', gettype($value)));
- }
-
- // Call file instance
- $data = $this->getBinaryFileInstance()->writeValueToFile($stackName, $value);
-
- // Return data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
- return $data;
- }
-
- /**
- * Writes given raw data to the file and returns a gap position and length
- *
- * @param $stackName Group identifier
- * @param $hash Hash from encoded value
- * @param $encoded Encoded value to be written to the file
- * @return $data Gap position and length of the raw data
- */
- public function writeDataToFreeGap (string $stackName, string $hash, string $encoded) {
- // Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: stackName=%s,hash=%s,encoded(%d)=%s - CALLED!', $stackName, $hash, strlen($encoded), $encoded));
-
- // Call file instance
- $data = $this->getBinaryFileInstance()->writeDataToFreeGap($stackName, $hash, $encoded);
-
- // Return data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: data[]=%s - EXIT!', gettype($data)));
- return $data;
- }
-
- /**
- * Searches for next suitable gap the given length of data can fit in
- * including padding bytes.
- *
- * @param $length Length of raw data
- * @return $seekPosition Found next gap's seek position
- * @throws InvalidArgumentException If a parameter is invalid
- */
- public function searchNextGap (int $length) {
- // Validate parameter
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: length=%d - CALLED!', $length));
- if ($length <= 0) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('length=%d is not valid', $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));
- return $seekPosition;
- }
-
- /**
- * Checks whether the abstracted file only contains gaps by counting all
- * gaps' bytes together and compare it to total length.
- *
- * @return $isGapsOnly Whether the abstracted file only contains gaps
- */
- public function isFileGapsOnly () {
- // Call file instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-ITERATOR: CALLED!');
- $isGapsOnly = $this->getBinaryFileInstance()->isFileGapsOnly();
-
- // Return position
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-ITERATOR: isGapsOnly=%d - EXIT!', $isGapsOnly));
- return $isGapsOnly;
- }
-
}
* @throws InvalidCommandException Thrown if even the default
* command class is missing (bad!)
*/
- protected function loadCommand ($commandName) {
+ protected function loadCommand (string $commandName) {
// Init command instance
$commandInstance = NULL;
// No news at main controller or non-news controller
$this->setClassName($className);
}
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('AFTER: controller=' . $this->getClassName());
// Is this class loaded?
+ //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('AFTER: controller=' . $this->getClassName());
if (!class_exists($this->getClassName())) {
// Throw an exception here
throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
+ }
// Try to read a config entry for our resolver including controller name... ;-)
$resolverConfigEntry = sprintf('%s_cmd_%s_resolver_class', strtolower($this->getClassPrefix()), strtolower($controllerName));
* @throws InvalidArgumentException Thrown if given controller is not set
* @throws DefaultControllerException Thrown if default controller was not found
*/
- protected function isControllerValid ($namespace, $controllerName) {
+ protected function isControllerValid (string $namespace, string $controllerName) {
// Is a action set?
if (empty($namespace)) {
// Then thrown an exception here
// Create class name
$className = sprintf(
- '%s\%sController',
+ '%s\%s%sController',
$namespace,
- $this->getCapitalizedClassPrefix() . StringUtils::convertToClassName($controllerName)
+ $this->getCapitalizedClassPrefix(),
+ StringUtils::convertToClassName($controllerName)
);
+
// Application's default news controller
$appDefaultControllerName = sprintf(
'%s\%sDefaultNewsController',
$namespace,
$this->getCapitalizedClassPrefix()
);
+
// Framework's default news controller
$defaultControllerName = sprintf(
'Org\Mxchange\CoreFramework\Controller\News\%sDefaultNewsController',
* @throws InvalidArgumentException Thrown if default controller is not set
* @throws InvalidControllerException Thrown if default controller is invalid
*/
- public static final function createConsoleControllerResolver ($namespace, $controllerName) {
+ public static final function createConsoleControllerResolver (string $namespace, string $controllerName) {
// Create the new instance
$resolverInstance = new ConsoleControllerResolver();
* @throws InvalidArgumentException Thrown if default controller is not set
* @throws InvalidControllerException Thrown if default controller is invalid
*/
- public static final function createHtmlControllerResolver ($namespace, $controllerName) {
+ public static final function createHtmlControllerResolver (string $namespace, string $controllerName) {
// Create the new instance
$resolverInstance = new HtmlControllerResolver();
* @throws InvalidArgumentException Thrown if default controller is not set
* @throws InvalidControllerException Thrown if default controller is invalid
*/
- public static final function createImageControllerResolver ($namespace, $controllerName) {
+ public static final function createImageControllerResolver (string $namespace, string $controllerName) {
// Create the new instance
$resolverInstance = new ImageControllerResolver();
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
-use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
use Org\Mxchange\CoreFramework\Stack\BaseStacker;
use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
+++ /dev/null
-<?php
-// Own namespace
-namespace Org\Mxchange\CoreFramework\Iterator\Filesystem;
-
-// Import SPL stuff
-use \SeekableIterator;
-
-/**
- * An interface for seekable iterators which also allow to write to the file
- * in different ways.
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface SeekableWritableFileIterator extends SeekableIterator {
- /**
- * Size of file stack
- *
- * @return $size Size (in bytes) of file
- */
- function size ();
-
- /**
- * Reads given amount of bytes from file.
- *
- * @param $bytes Amount of bytes to read
- * @return $data Data read from file
- */
- function read (int $bytes = 0);
-
- /**
- * Analyzes entries in index file. This will count all found (and valid)
- * entries, mark invalid as damaged and count gaps ("fragmentation"). If
- * only gaps are found, the file is considered as "virgin" (no entries).
- *
- * @return void
- */
- function analyzeFileStructure ();
-
- /**
- * Checks whether the file header is initialized
- *
- * @return $isInitialized Whether the file header is initialized
- */
- function isFileHeaderInitialized ();
-
- /**
- * Creates the assigned file
- *
- * @return void
- */
- function createFileHeader ();
-
- /**
- * Pre-allocates file (if enabled) with some space for later faster write access.
- *
- * @param $type Type of the file
- * @return void
- */
- function preAllocateFile (string $type);
-
- /**
- * Initializes counter for valid entries, arrays for damaged entries and
- * an array for gap seek positions. If you call this method on your own,
- * please re-analyze the file structure. So you are better to call
- * analyzeFileStructure() instead of this method.
- *
- * @return void
- */
- function initCountersGapsArray ();
-
- /**
- * Getter for header size
- *
- * @return $totalEntries Size of file header
- */
- function getHeaderSize ();
-
- /**
- * Setter for header size
- *
- * @param $headerSize Size of file header
- * @return void
- */
- function setHeaderSize (int $headerSize);
-
- /**
- * Getter for header array
- *
- * @return $totalEntries Size of file header
- */
- function getHeader ();
-
- /**
- * Setter for header
- *
- * @param $header Array for a file header
- * @return void
- */
- function setHeader (array $header);
-
- /**
- * Updates seekPosition attribute from file to avoid to much access on file.
- *
- * @return void
- */
- function updateSeekPosition ();
-
- /**
- * Getter for total entries
- *
- * @return $totalEntries Total entries in this file
- */
- function getCounter ();
-
- /**
- * "Getter" for file size
- *
- * @return $fileSize Size of currently loaded file
- */
- function getFileSize ();
-
- /**
- * Getter for seek position
- *
- * @return $seekPosition Current seek position (stored here in object)
- */
- function getSeekPosition ();
-
- /**
- * Searches for next suitable gap the given length of data can fit in
- * including padding bytes.
- *
- * @param $length Length of raw data
- * @return $seekPosition Found next gap's seek position
- */
- function searchNextGap (int $length);
-
- /**
- * Checks whether the abstracted file only contains gaps by counting all
- * gaps' bytes together and compare it to total length.
- *
- * @return $isGapsOnly Whether the abstracted file only contains gaps
- */
- function isFileGapsOnly();
-
- /**
- * Writes data at given position
- *
- * @param $seekPosition Seek position
- * @param $data Data to be written
- * @param $flushHeader Whether to flush the header (default: flush)
- * @return void
- */
- function writeData (int $seekPosition, string $data, bool $flushHeader = true);
-
- /**
- * 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 (int $seedPosition, string $data);
-
- /**
- * Writes given value to the file and returns a hash and gap position for it
- *
- * @param $groupId Group identifier
- * @param $value Value to be added to the stack
- * @return $data Hash and gap position
- */
- function writeValueToFile (string $groupId, $value);
-
- /**
- * Writes given raw data to the file and returns a gap position and length
- *
- * @param $groupId Group identifier
- * @param $hash Hash from encoded value
- * @param $encoded Encoded value to be written to the file
- * @return $data Gap position and length of the raw data
- */
- function writeDataToFreeGap (string $groupId, string $hash, string $encoded);
-
-}