/**
* Initializes this file class
*
- * @param $infoInstance An instance of a SplFileInfo class
+ * @param $fileInfoInstance An instance of a SplFileInfo class
* @return void
*/
- protected function initFile (SplFileInfo $infoInstance) {
+ protected function initFile (SplFileInfo $fileInfoInstance) {
// Get a file i/o pointer instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: infoInstance=%s - CALLED!', $infoInstance));
- $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($infoInstance));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
+ $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileInfoInstance));
// ... and set it here
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Setting pointerInstance=%s ...', $pointerInstance->__toString()));
$this->setPointerInstance($pointerInstance);
// Trace message
* @param $data Data to be written
* @param $flushHeader Whether to flush the header (default: flush)
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
*/
public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
- // Write data at given position
+ // Validate parameter
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%s,data()=%d,flushHeader=%d - CALLED!', $seekPosition, strlen($data), intval($flushHeader)));
+ if ($seekPosition < 0) {
+ // Invalid seek position
+ throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid', $seekPosition));
+ } elseif (empty($data)) {
+ // Empty data is invalid, too
+ throw new InvalidArgumentException('Parameter "data" is empty');
+ }
+
+ // Write data at given position
$this->getPointerInstance()->writeAtPosition($seekPosition, $data);
// Increment counter
*
* @param $length Length of the block
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
*/
protected function markCurrentBlockAsEmpty (int $length) {
- // Get current seek position
+ // Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d - CALLED!', $length));
+ if ($length < 1) {
+ // Length cannot below one
+ throw new InvalidArgumentException(sprintf('length=%d is not valid', $length));
+ }
+
+ // Get current seek position
$currentPosition = $this->key();
// Now add it as gap entry
if ($this->isFileInitialized()) {
// Some bytes has been written, so rewind to start of it.
$rewindStatus = $this->rewind();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('rewindStatus=%s', $rewindStatus));
// Is the rewind() call successfull?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: rewindStatus=%d', $rewindStatus));
if ($rewindStatus != 1) {
// Something bad happened
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Could not rewind().'));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Could not rewind().');
}
// Read file header
}
// Return result
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('isInitialized=%d - EXIT!', intval($isInitialized)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized)));
return $isInitialized;
}
* @return $isInitialized Whether the file's size is zero
*/
public function isFileInitialized () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-
// Get it from iterator which holds the pointer instance. If false is returned
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
$fileSize = $this->size();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileSize=%s', $fileSize));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: fileSize=%s', $fileSize));
/*
* The returned file size should not be false or NULL as this means
$isInitialized = ($fileSize > 0);
// Return result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('isInitialized=%d - EXIT!', intval($isInitialized)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: isInitialized=%d - EXIT!', intval($isInitialized)));
return $isInitialized;
}
* @return void
*/
public function createFileHeader () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
-
// The file's header should not be initialized here
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
assert(!$this->isFileHeaderInitialized());
// Simple flush file header which will create it.
// Rewind seek position (to beginning of file) and update/flush file header
$this->rewindUpdateSeekPosition();
+ // Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
}
*
* @param $type Type of the file
* @return void
+ * @throws InvalidArgumentException If a parameter is empty
*/
public function preAllocateFile (string $type) {
// Is it enabled?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
- // Not enabled
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Not pre-allocating file.'));
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: type=%s - CALLED!', $type));
+ if (empty($type)) {
+ // Empty type
+ throw new InvalidArgumentException('Parameter "type" is empty');
+ } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_enabled') != 'Y') {
// Don't continue here.
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Not pre-allocating file.'));
return;
}
// Message to user
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Pre-allocating file ...'));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
// Calculate minimum length for one entry
$minLengthEntry = $this->getBlockInstance()->calculateMinimumBlockLength();
// Calulcate seek position
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('minLengthEntry=%s', $minLengthEntry));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: minLengthEntry=%s', $minLengthEntry));
$seekPosition = $minLengthEntry * FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($type . '_pre_allocate_count');
// Now simply write a NUL there. This will pre-allocate the file.
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('seekPosition=%s', $seekPosition));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: seekPosition=%d', $seekPosition));
$this->writeData($seekPosition, chr(0));
// Rewind seek position (to beginning of file) and update/flush file header
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- public function read (int $bytes = NULL) {
+ public function read (int $bytes = 0) {
// Call pointer instance
return $this->getPointerInstance()->read($bytes);
}
*/
public final static function createIndexFile (SplFileInfo $fileInfoInstance, Block $blockInstance) {
// Get a new instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance=%s,blockInstance=%s - CALLED!', $fileInfoInstance, $blockInstance->__toString()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('INDEX-FILE: fileInfoInstance[%s]=%s,blockInstance=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $blockInstance->__toString()));
$fileInstance = new IndexFile();
// Set block instance here for callbacks
return $this->getPointerInstance()->getFileObject();
}
+ /**
+ * Getter for file's name
+ */
+ public final function getFilename () {
+ // Invole file object's method
+ return $this->getFileObject()->getFilename();
+ }
+
/**
* Close a file source and set it's instance to null and the file name
* to empty
* @return void
*/
public function closeFile () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
-
// Close down pointer instance as well by unsetting it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: CALLED!');
$this->unsetPointerInstance();
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__));
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-ABSTRACT-FILE: EXIT!');
}
/**
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
// Seek to position
$status = $this->getFileObject()->fseek($offset, $whence);
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- public function read (int $bytes = NULL) {
+ public function read (int $bytes = 0) {
// Try to read given characters
$data = $this->getFileObject()->fread($bytes);
* @throws NullPointerException If the file pointer instance is not set by setFileObject()
* @throws InvalidResourceException If there is no object being set
*/
- public function read (int $bytes = NULL) {
+ public function read (int $bytes = 0) {
// Some sanity checks
if (is_null($this->getFileObject())) {
// Pointer not initialized
}
// Is $bytes set?
- if (is_int($bytes)) {
+ if ($bytes > 0) {
// Try to read given characters
$data = $this->getFileObject()->fread($bytes);
} else {
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
// Import SPL stuff
+use \InvalidArgumentException;
use \SplFileInfo;
+use \UnexpectedValueException;
/**
* A class for reading files
if ((is_null($fileObject)) || ($fileObject === false)) {
// Something bad happend
throw new FileIoException($fileInstance->getPathname(), self::EXCEPTION_FILE_POINTER_INVALID);
- } // END - if
+ }
// Create new instance
$pointerInstance = new FrameworkFileInputOutputPointer();
return $pointerInstance;
}
- /**
- * Validates file pointer and throws exceptions. This method does not return
- * anything (not reliable) as this method checks the file pointer and on
- * case of an error it throws an exception. If this method does not throw
- * any exceptions, the file pointer seems to be fine.
- *
- * @return void
- * @throws NullPointerException If the file pointer instance
- * is not set by setFileObject()
- * @todo Add more checks
- */
- private function validateFilePointer () {
- if (is_null($this->getFileObject())) {
- // Pointer not initialized
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
-
- // All fine here
- }
-
/**
* Read 1024 bytes data from a file pointer
*
* @return mixed The result of fread()
*/
public function readFromFile () {
- // Validate the pointer
- $this->validateFilePointer();
-
// Read data from the file pointer and return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
return $this->read(1024);
}
* @return mixed Number of writes bytes or false on error
*/
public function writeToFile (string $dataStream) {
- // Validate the pointer
- $this->validateFilePointer();
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: dataStream(%d)=%s - CALLED!', strlen($dataStream), $dataStream));
+ if (empty($dataStream)) {
+ // Empty dataStream
+ throw new InvalidArgumentException('Parameter "dataStream" is empty');
+ }
// Write data to the file pointer and return written bytes
- return $this->getFileObject()->fwrite($dataStream, strlen($dataStream));
+ $status = $this->getFileObject()->fwrite($dataStream, strlen($dataStream));
+
+ // Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status));
+ return $status;
}
/**
* Writes at given position by seeking to it.
*
* @param $seekPosition Seek position in file
- * @param $data Data to be written
+ * @param $dataStream Data to be written
* @return mixed Number of writes bytes or false on error
+ * @throws InvalidArgumentException If a parameter is not valid
*/
- public function writeAtPosition (int $seekPosition, string $data) {
+ public function writeAtPosition (int $seekPosition, string $dataStream) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream()=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
+ if ($seekPosition < 0) {
+ // Invalid seek position
+ throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ } elseif (empty($dataStream)) {
+ // Empty dataStream
+ throw new InvalidArgumentException('Parameter "dataStream" is empty');
+ }
+
// First seek to it
- $this->seek($seekPosition);
+ if (!$this->seek($seekPosition)) {
+ // Could not seek
+ throw new InvalidArgumentException(sprintf('Could not seek to seekPosition=%d', $seekPosition));
+ }
// Then write the data at that position
- return $this->writeToFile($data);
+ $status = $this->writeToFile($dataStream);
+
+ // Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status));
+ return $status;
}
/**
* @return $status Status of this operation
*/
public function rewind () {
- // Validate the pointer
- $this->validateFilePointer();
-
// Rewind the pointer
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
return $this->getFileObject()->rewind();
}
* @param $seekPosition Seek position in file
* @param $whence "Seek mode" (see http://de.php.net/fseek)
* @return $status Status of this operation
+ * @throws InvalidArgumentException If a parameter is not valid
*/
- public function seek ($seekPosition, $whence = SEEK_SET) {
- // Validate the pointer
- $this->validateFilePointer();
+ public function seek (int $seekPosition, int $whence = SEEK_SET) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,whence=%d - CALLED!', $seekPosition, $whence));
+ if ($seekPosition < 0) {
+ // Invalid seek position
+ throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ }
// Move the file pointer
- return $this->getFileObject()->fseek($seekPosition, $whence);
+ $status = $this->getFileObject()->fseek($seekPosition, $whence);
+
+ // Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: status[%s]=%d - EXIT!', gettype($status), $status));
+ return $status;
}
/**
*/
public function readLine () {
// Read whole line
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
return $this->read();
}
*
* @param $bytes Amount of bytes to read
* @return $data Data read from file
+ * @throws InvalidArgumentException If a parameter is invalid
*/
- public function read (int $bytes = NULL) {
- // Validate the pointer
- $this->validateFilePointer();
+ public function read (int $bytes = 0) {
+ // Validatre parameter
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: bytes=%d - CALLED!', $bytes));
+ if ($bytes < 0) {
+ // Bytes cannot be lesser than zero
+ throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+ }
// Is $bytes set?
- if (is_int($bytes)) {
+ if ($bytes > 0) {
// Try to read given characters
$data = $this->getFileObject()->fread($bytes);
} else {
}
// Then return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: data[%s]=%s - EXIT!', gettype($data), $data));
return $data;
}
* "Getter" for file size
*
* @return $fileSize Size of currently loaded file
+ * @throws UnexpectedValueException If $fileData does not contain "size"
*/
public function getFileSize () {
- // Check if the pointer is still valid
- $this->validateFilePointer();
-
// Get file's data
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: CALLED!');
$fileData = $this->getFileObject()->fstat();
// Make sure the required array key is there
- assert(isset($fileData['size']));
+ if (!isset($fileData['size'])) {
+ // Not valid array
+ throw new UnexpectedValueException(sprintf('fileData=%s has no element "size"', print_r($fileData, TRUE)));
+ }
// Return size
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILE-INPUT-OUTPUT-POINTER: fileData[size]=%d - EXIT!', $fileData['size']);
return $fileData['size'];
}
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
$this->partialStub('offset=' . $offset . ',whence=' . $whence);
}
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
// Not possible in text files
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEXT-FILE: offset=' . $offset . ',whence=' . $whence);
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
* @return $lineArray An indexed array with the read line
*/
public function readCsvFileLine (string $columnSeparator) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] columnSeparator=%s - CALLED!', __METHOD__, __LINE__, $columnSeparator));
-
// Read raw line
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] columnSeparator=%s - CALLED!', __METHOD__, __LINE__, $columnSeparator));
$data = $this->getPointerInstance()->readLine();
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d', __METHOD__, __LINE__, strlen($data)));
-
// Parse data
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d', __METHOD__, __LINE__, strlen($data)));
$lineArray = $this->parseDataToIndexedArray($data, $columnSeparator);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] lineArray()=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
-
// Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] lineArray()=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
return $lineArray;
}
* @return $lineArray An indexed array with the read line
*/
private function parseDataToIndexedArray (string $data, string $columnSeparator) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d,columnSeparator=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $columnSeparator));
-
// Init return array
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d,columnSeparator=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $columnSeparator));
$lineArray = [];
// Whether the parser reads a quoted string (which may contain the column separator again)
// "Cache" char
$char = substr($data, $idx, 1);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] idx=%s,char=%s ...', __METHOD__, __LINE__, $idx, $char));
-
// Is the column separator found and not within quotes?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] idx=%d,char=%s ...', __METHOD__, __LINE__, $idx, $char));
if (($isInQuotes === false) && ($char == $columnSeparator)) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
-
// Add this line to the array
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
array_push($lineArray, $column);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - After add!', __METHOD__, __LINE__, count($lineArray)));
-
// Clear variable ...
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - After add!', __METHOD__, __LINE__, count($lineArray)));
$column = '';
// ... and skip it
continue;
} elseif ($char == chr(34)) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] column=%s ...', __METHOD__, __LINE__, $column));
-
// $column must be empty at this point if we are at starting quote
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] column=%s ...', __METHOD__, __LINE__, $column));
assert(($isInQuotes === true) || (empty($column)));
// Double-quote found, so flip variable
$isInQuotes = (!$isInQuotes);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] isInQuotes=%d ...', __METHOD__, __LINE__, intval($isInQuotes)));
-
// Skip double-quote (escaping of them is not yet supported)
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] isInQuotes=%d ...', __METHOD__, __LINE__, intval($isInQuotes)));
continue;
}
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding char=%s ...', __METHOD__, __LINE__, $idx, $char));
-
// Add char to column
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding char=%s ...', __METHOD__, __LINE__, $idx, $char));
$column .= $char;
- } // END - for
+ }
// Is there something outstanding?
if (!empty($column)) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
-
// Then don't forget this. :-)
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Adding column=%s ...', __METHOD__, __LINE__, $column));
array_push($lineArray, $column);
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - After add!', __METHOD__, __LINE__, count($lineArray)));
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
+ }
// Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] line[]=%d - EXIT!', __METHOD__, __LINE__, count($lineArray)));
return $lineArray;
}
*/
protected function initIndex (SplFileInfo $fileInfoInstance) {
// Get a file i/o pointer instance for index file
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileInfoInstance=%s - CALLED!', $fileInfoInstance));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
$fileInstance = ObjectFactory::createObjectByConfiguredName('index_file_class', array($fileInfoInstance, $this));
// Get iterator instance
*/
public final static function createFileStackIndex (SplFileInfo $fileInfoInstance) {
// Get a new instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance=%s - CALLED!', $fileInfoInstance));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-INDEX: fileInfoInstance[%s]=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance));
$indexInstance = new FileStackIndex();
// Initialize index
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- public function read (int $bytes = NULL) {
+ public function read (int $bytes = 0) {
// Call block instance
return $this->getBlockInstance()->read($bytes);
}
* @return $status Status of file seek: 0 = success, -1 = failed
* @throws UnsupportedOperationException If this method is called
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return $status Status of file seek: 0 = success, -1 = failed
* @throws UnsupportedOperationException If this method is called
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-CONSOLE-OUTPUT: offset=' . $offset . ',whence=' . $whence);
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return $status Status of file seek: 0 = success, -1 = failed
* @throws UnsupportedOperationException If this method is called
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-ERROR-LOG-OUTPUT: offset=' . $offset . ',whence=' . $whence);
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return $status Status of file seek: 0 = success, -1 = failed
* @throws UnsupportedOperationException If this method is called
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEBUG-WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
* @return $status Status of file seek: 0 = success, -1 = failed
* @throws UnsupportedOperationException If this method is called
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WEB-OUTPUT: offset=' . $offset . ',whence=' . $whence);
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
+use \InvalidArgumentException;
use \SplFileInfo;
use \UnexpectedValueException;
* @param $fileInfoInstance An instance of a SplFileInfo class
* @param $type Type of this stack (e.g. url_source for URL sources)
* @return void
+ * @throws InvalidArgumentException If a parameter is invalid
* @todo Currently the stack file is not cached, please implement a memory-handling class and if enough RAM is found, cache the whole stack file.
*/
protected function initFileStack (SplFileInfo $fileInfoInstance, string $type) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance[%s]=%s,type=%s - CALLED!', get_class($fileInfoInstance), $fileInfoInstance, $type));
+ if (empty($type)) {
+ // Invalid parameter
+ throw new InvalidArgumentException('Parameter "type" is empty');
+ }
+
// Get a stack file instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: fileInfoInstance=%s,type=%s - CALLED!', $fileInfoInstance, $type));
- $fileInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileInfoInstance, $this));
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('stack_file_class', array($fileInfoInstance, $this));
// Get iterator instance
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($fileInstance));
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('file_iterator_class', array($stackInstance));
// Set iterator here
$this->setIteratorInstance($iteratorInstance);
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
*/
- function seek ($offset, $whence = SEEK_SET);
+ function seek (int $offset, int $whence = SEEK_SET);
/**
* Size of file stack
* is not set by setFileObject()
* @throws InvalidResourceException If there is being set
*/
- function read (int $bytes = NULL);
+ function read (int $bytes = 0);
}
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- function read (int $bytes);
+ function read (int $bytes = 0);
/**
* Analyzes entries in index file. This will count all found (and valid)
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
*/
- public function seek ($offset, $whence = SEEK_SET) {
+ public function seek (int $offset, int $whence = SEEK_SET) {
$this->partialStub('offset=' . $offset . ',whence=' . $whence);
}