3 namespace Org\Mxchange\CoreFramework\Filesystem\File;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
7 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
8 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
14 * A general text file class
16 * @author Roland Haeder <webmaster@ship-simu.org>
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.ship-simu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 abstract class BaseTextFile extends BaseAbstractFile {
37 * Protected constructor
39 * @param $className Name of the class
42 protected function __construct (string $className) {
43 // Call parent constructor
44 parent::__construct($className);
48 * Determines seek position
50 * @return $seekPosition Current seek position
52 public function determineSeekPosition () {
53 // Not possible in text files
54 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
58 * Seek to given offset (default) or other possibilities as fseek() gives.
60 * @param $offset Offset to seek to (or used as "base" for other seeks)
61 * @param $whence Added to offset (default: only use offset to seek to)
62 * @return $status Status of file seek: 0 = success, -1 = failed
64 public function seek (int $offset, int $whence = SEEK_SET) {
65 // Not possible in text files
66 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEXT-FILE: offset=' . $offset . ',whence=' . $whence);
67 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);
71 * Reads from a local or remote file
73 * @param $infoInstance An instance of a SplFileInfo class
74 * @return $array An array containing all read lines
75 * @throws InvalidArrayCountException If an array has not the expected size
76 * @throws InvalidMD5ChecksumException If two MD5 hashes did not match
78 public function loadFileContents (SplFileInfo $infoInstance) {
80 * This class (or its implementations) are special file readers/writers.
81 * There is no need to read/write the whole file.
83 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEXT-FILE: infoInstance=' . $infoInstance);
84 throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION);