<?php
// Own namespace
-namespace Org\Mxchange\CoreFramework\Stacker\Filesystem;
+namespace Org\Mxchange\CoreFramework\Stack\File;
// Import framework stuff
-use Org\Mxchange\CoreFramework\Factory\Filesystem\Stack\FileStackIndexFactory;
+use Org\Mxchange\CoreFramework\Factory\Stack\File\FileStackIndexFactory;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
-use Org\Mxchange\CoreFramework\FileStack\InvalidMagicException;
use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
use Org\Mxchange\CoreFramework\Index\Indexable;
use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
-use Org\Mxchange\CoreFramework\Stacker\BaseStacker;
+use Org\Mxchange\CoreFramework\Stack\BaseStacker;
+use Org\Mxchange\CoreFramework\Stack\File\InvalidMagicException;
+use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
* 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 BaseFileStack extends BaseStacker {
+abstract class BaseFileStack extends BaseStacker implements StackableFile {
// Load traits
use IteratorTrait;
// Exception codes
const EXCEPTION_BAD_MAGIC = 0xe100;
- /**
- * Magic for this stack
- */
- const STACK_MAGIC = 'STACKv0.1';
-
- /**
- * Name of array index for gap position
- */
- const ARRAY_INDEX_GAP_POSITION = 'gap';
-
- /**
- * Name of array index for hash
- */
- const ARRAY_INDEX_HASH = 'hash';
-
- /**
- * Name of array index for length of raw data
- */
- const ARRAY_INDEX_DATA_LENGTH = 'length';
-
/**
* An instance of an Indexable class
*/
*/
$header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data);
- // Set header here
- $this->getIteratorInstance()->setHeader($header);
-
// Check if the array has only 3 elements
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: header(%d)=%s', count($header), print_r($header, true)));
if (count($header) != 3) {
$data,
count($header)
));
- } elseif ($header[0] != self::STACK_MAGIC) {
+ } elseif ($header[0] != StackableFile::STACK_MAGIC) {
// Bad magic
throw new InvalidMagicException($data, self::EXCEPTION_BAD_MAGIC);
}
$header[1] = hex2bin($header[1]);
$header[2] = hex2bin($header[2]);
+ // Set header here
+ $this->getIteratorInstance()->setHeader($header);
+
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: EXIT!', __METHOD__, __LINE__));
}
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: CALLED!', __METHOD__, __LINE__));
$header = sprintf('%s%s%s%s%s%s',
// Magic
- self::STACK_MAGIC,
+ StackableFile::STACK_MAGIC,
// Separator magic<->count
chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
// Calculate header size
$this->getIteratorInstance()->setHeaderSize(
- strlen(self::STACK_MAGIC) +
+ strlen(StackableFile::STACK_MAGIC) +
strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
BaseBinaryFile::LENGTH_COUNT +
strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
- * @throws EmptyStackerException If the stack is empty
+ * @throws BadMethodCallException If the stack is empty
*/
protected function getLastValue (string $stackerName) {
// Is the stack not yet initialized or full?
if ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
} // END - if
// Now get the last value
*
* @param $stackerName Name of the stack
* @return $value Value of last added value
- * @throws EmptyStackerException If the stack is empty
+ * @throws BadMethodCallException If the stack is empty
*/
protected function getFirstValue (string $stackerName) {
// Is the stack not yet initialized or full?
if ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
} // END - if
// Now get the first value
*
* @param $stackerName Name of the stack
* @return $value Value "poped" from array
- * @throws EmptyStackerException If the stack is empty
+ * @throws BadMethodCallException If the stack is empty
*/
protected function popLast (string $stackerName) {
// Is the stack not yet initialized or full?
if ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
} // END - if
// Now, remove the last entry, we don't care about the return value here, see elseif() block above
*
* @param $stackerName Name of the stack
* @return $value Value "shifted" from array
- * @throws EmptyStackerException If the named stacker is empty
+ * @throws BadMethodCallException If the named stacker is empty
*/
protected function popFirst (string $stackerName) {
// Is the stack not yet initialized or full?
if ($this->isStackEmpty($stackerName)) {
// Throw an exception
- throw new EmptyStackerException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
+ throw new BadMethodCallException(array($this, $stackerName), self::EXCEPTION_STACKER_IS_EMPTY);
} // END - if
// Now, remove the last entry, we don't care about the return value here, see elseif() block above
// Return gap position, hash and length of raw data
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: groupId=%s,hash=%s,rawData()=%d - EXIT!', $groupId, $hash, strlen($rawData)));
return [
- self::ARRAY_INDEX_GAP_POSITION => $gapPosition,
- self::ARRAY_INDEX_HASH => $hash,
- self::ARRAY_INDEX_DATA_LENGTH => strlen($rawData),
+ self::ARRAY_NAME_GAP_POSITION => $gapPosition,
+ self::ARRAY_NAME_HASH => $hash,
+ self::ARRAY_NAME_DATA_LENGTH => strlen($rawData),
];
}