// Import SPL stuff
use \InvalidArgumentException;
use \SplFileInfo;
+use \OutOfBoundsException;
use \UnexpectedValueException;
/**
* @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) {
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
if ($seekPosition < 0) {
// Invalid seek position
- throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
} elseif (empty($dataStream)) {
// Empty dataStream
throw new InvalidArgumentException('Parameter "dataStream" is empty');
* @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
+ * @throws OutOfBoundsException If the position is not seekable
*/
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));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid.', $seekPosition));
}
// Move the file pointer
*
* @param $bytes Amount of bytes to read
* @return $data Data read from file
- * @throws InvalidArgumentException If a parameter is invalid
+ * @throws OutOfBoundsException If the position is not seekable
*/
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));
+ throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
}
// Is $bytes bigger than zero?