use Org\Mxchange\CoreFramework\Filesystem\Block;
use Org\Mxchange\CoreFramework\Filesystem\Block\CalculatableBlock;
use Org\Mxchange\CoreFramework\Filesystem\File\BaseAbstractFile;
+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\Stack\StackableTrait;
// Import SPL stuff
use \BadMethodCallException;
use \InvalidArgumentException;
+use \LogicException;
use \SplFileInfo;
use \UnexpectedValueException;
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-abstract class BaseBinaryFile extends BaseAbstractFile {
+abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile {
+ // Load traits
+ use StackableTrait;
+ use IndexableStackTrait;
+
/**
* Separator for header data
*/
*/
private $currentBlock = '';
- /**
- * An instance of a Block class
- */
- private $blockInstance = NULL;
-
/**
* Protected constructor
*
$this->initCountersGapsArray();
}
- /**
- * Setter for Block instance
- *
- * @param $blockInstance An instance of an Block class
- * @return void
- */
- protected final function setBlockInstance (Block $blockInstance) {
- $this->blockInstance = $blockInstance;
- }
-
- /**
- * Getter for Block instance
- *
- * @return $blockInstance An instance of an Block class
- */
- public final function getBlockInstance () {
- return $this->blockInstance;
- }
-
/**
* Setter for backBuffer field
*
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Pre-allocating file ...');
// Calculate minimum length for one entry and get file size
- $minimumBlockLength = $this->getBlockInstance()->calculateMinimumBlockLength();
+ $minimumBlockLength = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
$fileSize = $this->getFileSize();
// Calulcate seek position
// First calculate minimum block length
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d', $this->determineSeekPosition()));
- $length = $this->getBlockInstance()->calculateMinimumBlockLength();
+ $length = $this->getIndexableStackInstance()->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->getBlockInstance()->calculateMinimumBlockLength();
+ $length = $this->getIndexableStackInstance()->calculateMinimumBlockLength();
// Short be more than zero!
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: length=%d', $length));
* Reads the file header
*
* @return void
+ * @throws LogicException If both instances are not set
*/
public function readFileHeader () {
- // Call block instance
+ // Is index set or stack?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- $this->getBlockInstance()->readFileHeader();
+ if ($this->getIndexableStackInstance() instanceof IndexableStack) {
+ // Call index instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->indexableStackInstance->readFileHeader() ...');
+ $this->getIndexableStackInstance()->readFileHeader();
+ } 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();
+ } else {
+ // Bad logic?
+ throw new LogicException('Wether indexableStackInstance nor stackableFileInstance are set');
+ }
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');
public function flushFileHeader () {
// Call block instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: CALLED!');
- $this->getBlockInstance()->flushFileHeader();
+ $this->getIndexableStackInstance()->flushFileHeader();
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: EXIT!');