X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ffile_directories%2Fclass_BaseFileIo.php;h=d52d02fa1b00c7e6d5ef8c9caa0d5eed68ef3967;hp=b3b676dd99527ed16b7e8ecb79d5cac675c338b2;hb=5203f9bd014ad46fbc7ee54e7223dcd46e14e3b4;hpb=b306775c8bca74cc966be6e31cc13ca688573193 diff --git a/inc/classes/main/file_directories/class_BaseFileIo.php b/inc/classes/main/file_directories/class_BaseFileIo.php index b3b676dd..d52d02fa 100644 --- a/inc/classes/main/file_directories/class_BaseFileIo.php +++ b/inc/classes/main/file_directories/class_BaseFileIo.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -61,14 +61,16 @@ class BaseFileIo extends BaseFrameworkSystem { /** * Close a file source and set it's instance to null and the file name - * to empty + * to empty. * * @return void - * @throws NullPointerException If the file pointer instance - * is not set by setPointer() + * @throws NullPointerException If the file pointer instance is not set by setPointer() * @throws InvalidResourceException If there is being set */ - public function closeFile () { + private function closeFile () { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileName())); + if (is_null($this->getPointer())) { // Pointer not initialized throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); @@ -77,10 +79,16 @@ class BaseFileIo extends BaseFrameworkSystem { throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE); } + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: Closing file %s ...', __METHOD__, __LINE__, $this->getFileName())); + // Close the file pointer and reset the instance variable @fclose($this->getPointer()); $this->setPointer(NULL); $this->setFileName(''); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__)); } /** @@ -89,15 +97,14 @@ class BaseFileIo extends BaseFrameworkSystem { * @param $filePointer File resource * @return void */ - public final function setPointer ($filePointer) { + protected final function setPointer ($filePointer) { $this->filePointer = $filePointer; } /** * Getter for the file pointer * - * @return $filePointer The file pointer which shall be a valid - * file resource + * @return $filePointer The file pointer which shall be a valid file resource */ public final function getPointer () { return $this->filePointer; @@ -109,7 +116,7 @@ class BaseFileIo extends BaseFrameworkSystem { * @param $fileName The new file name * @return void */ - public final function setFileName ($fileName) { + protected final function setFileName ($fileName) { $fileName = (string) $fileName; $this->fileName = $fileName; } @@ -124,14 +131,23 @@ class BaseFileIo extends BaseFrameworkSystem { } /** - * "Getter" for seek position + * Determines seek position * * @return $seekPosition Current seek position */ - public final function getSeekPosition () { + public final function determineSeekPosition () { return ftell($this->getPointer()); } + /** + * Determines whether the EOF has been reached + * + * @return $isEndOfFileReached Whether the EOF has been reached + */ + public final function isEndOfFileReached () { + return feof($this->getPointer()); + } + /** * Seek to given offset (default) or other possibilities as fseek() gives. * @@ -144,6 +160,7 @@ class BaseFileIo extends BaseFrameworkSystem { $status = fseek($this->getPointer(), $offset, $whence); // Return status + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] status=%d', __METHOD__, __LINE__, $status)); return $status; } @@ -151,21 +168,26 @@ class BaseFileIo extends BaseFrameworkSystem { * Size of this file * * @return $size Size (in bytes) of file + * @todo Handle seekStatus */ public function size () { + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__)); + // Get current seek position - $seekPosition = $this->getSeekPosition(); + $seekPosition = $this->determineSeekPosition(); // Seek to end - $this->seek(0, SEEK_END); + $seekStatus = $this->seek(0, SEEK_END); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekStatus=%d', __METHOD__, __LINE__, $seekStatus)); // Get position again (which is the end of the file) - $size = $this->getSeekPosition(); + $size = $this->determineSeekPosition(); // Reset seek position to old $this->seek($seekPosition); // Return size + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] size=%s - EXIT!', __METHOD__, __LINE__, $size)); return $size; } }