use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
-use Org\Mxchange\CoreFramework\Filesystem\Block;
-use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
+use Org\Mxchange\CoreFramework\Index\Indexable;
use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
-use Org\Mxchange\CoreFramework\Index\Stack\IndexableStack;
-use Org\Mxchange\CoreFramework\Traits\Index\Stack\IndexableStackTrait;
+use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
use Org\Mxchange\CoreFramework\Traits\Stack\StackableTrait;
// Import SPL stuff
use \BadMethodCallException;
use \InvalidArgumentException;
use \LogicException;
+use \OutOfBoundsException;
use \SplFileInfo;
use \UnexpectedValueException;
abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
// Load traits
use StackableTrait;
- use IndexableStackTrait;
+ use IndexableTrait;
/**
* Separator for header data
* @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 invalid
*/
public function writeData (int $seekPosition, string $data, bool $flushHeader = true) {
/* 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));
+ throw new OutOfBoundsException(sprintf('seekPosition=%d is not valid', $seekPosition));
} elseif (empty($data)) {
// Empty data is invalid, too
throw new InvalidArgumentException('Parameter "data" is empty');
* @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('BASE-BINARY-FILE: 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');
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
// Calculate minimum length for one entry and get file size
- $minimumBlockLength = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+ $minimumBlockLength = $this->getIndexInstance()->calculateMinimumBlockLength();
$fileSize = $this->getFileSize();
// Calulcate seek position
* @param $offset Offset to seek to (or used as "base" for other seeks)
* @param $whence Added to offset (default: only use offset to seek to)
* @return $status Status of file seek: 0 = success, -1 = failed
- * @throws InvalidArgumentException If a parameter is not valid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function seek (int $offset, int $whence = SEEK_SET) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: offset=%d,whence=%d - CALLED!', $offset, $whence));
if ($offset < 0) {
// No offset is smaller than zero
- throw new InvalidArgumentException(sprintf('offset=%d is not valid', $offset));
+ throw new OutOfBoundsException(sprintf('offset=%d is not valid', $offset));
}
// Call pointer instance
*
* @param $bytes Amount of bytes to read
* @return $data Data read from file
- * @throws InvalidArgumentException If a parameter is not valid
+ * @throws OutOfBoundsException If the position is not seekable
*/
public function read (int $bytes = 0) {
// Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: bytes=%d - CALLED!', $bytes));
if ($bytes < 0) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('bytes=%d is not valid', $bytes));
+ // Throw exception
+ throw new OutOfBoundsException(sprintf('bytes=%d is not valid', $bytes));
}
// Call pointer instance
// First calculate minimum block length
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d', $this->determineSeekPosition()));
- $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+ $length = $this->getIndexInstance()->calculateMinimumBlockLength();
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
// Read possibly back-buffered bytes from previous call of next().
public function isValid () {
// First calculate minimum block length
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
+ $length = $this->getIndexInstance()->calculateMinimumBlockLength();
// Short be more than zero!
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
public function readFileHeader () {
// Is index set or stack?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- if ($this->getIndexableStackInstance() instanceof IndexableStack) {
+ if ($this->getIndexInstance() instanceof Indexable) {
// Call index instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexableStackInstance->readFileHeader() ...');
- $this->getIndexableStackInstance()->readFileHeader();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexInstance->readIndexHeader() ...');
+ $this->getIndexInstance()->readIndexHeader();
} elseif ($this->getStackInstance() instanceof StackableFile) {
// Call stacke instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->stackInstance->readFileHeader() ...');
- $this->getStackInstance()->readFileHeader();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->stackInstance->readStackHeader() ...');
+ $this->getStackInstance()->readStackHeader();
} else {
// Bad logic?
- throw new LogicException('Wether indexableStackInstance nor stackableFileInstance are set');
+ throw new LogicException('Wether indexInstance nor stackInstance are set');
}
// Trace message
public function flushFileHeader () {
// Call block instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- $this->getIndexableStackInstance()->flushFileHeader();
+ $this->getIndexInstance()->flushFileHeader();
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');