X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=framework%2Fmain%2Fclasses%2Fstacker%2Ffile%2Fclass_BaseFileStack.php;fp=framework%2Fmain%2Fclasses%2Fstacker%2Ffile%2Fclass_BaseFileStack.php;h=badedcb7c0032ba1dd6962bc5609788a9343b4ca;hb=4966b4ec26e66d4ebd459ad4b75d3f520bdc6681;hp=c82e62c30c6f6999c75f79a328b9d51622793536;hpb=26a7b8b3c66456617d23f38f61079cf5a2fac491;p=core.git diff --git a/framework/main/classes/stacker/file/class_BaseFileStack.php b/framework/main/classes/stacker/file/class_BaseFileStack.php index c82e62c3..badedcb7 100644 --- a/framework/main/classes/stacker/file/class_BaseFileStack.php +++ b/framework/main/classes/stacker/file/class_BaseFileStack.php @@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Stack\File; use Org\Mxchange\CoreFramework\Factory\Stack\File\FileStackIndexFactory; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile; +use Org\Mxchange\CoreFramework\Filesystem\File\BinaryFile; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; use Org\Mxchange\CoreFramework\Stack\BaseStacker; use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait; @@ -100,11 +101,11 @@ abstract class BaseFileStack extends BaseStacker { // Last character must be the separator /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: data(-1)=%s', dechex(ord(substr($data, -1, 1))))); - if (substr($data, -1, 1) !== chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) { + if (substr($data, -1, 1) !== chr(BinaryFile::SEPARATOR_HEADER_ENTRIES)) { // Not valid separator throw new UnexpectedValueException(sprintf('data=%s does not have separator=%s at the end.', $data, - BaseBinaryFile::SEPARATOR_HEADER_ENTRIES + BinaryFile::SEPARATOR_HEADER_ENTRIES )); } @@ -122,7 +123,7 @@ abstract class BaseFileStack extends BaseStacker { * 1 => total entries * 2 => current seek position */ - $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data); + $header = explode(chr(BinaryFile::SEPARATOR_HEADER_DATA), $data); // 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))); @@ -138,19 +139,19 @@ abstract class BaseFileStack extends BaseStacker { } // Check length of count and seek position - if (strlen($header[1]) != BaseBinaryFile::LENGTH_COUNT) { + if (strlen($header[1]) != BinaryFile::LENGTH_COUNT) { // Count length not valid throw new UnexpectedValueException(sprintf('header[1](%d)=%s is not expected %d length', strlen($header[1]), $header[1], - BaseBinaryFile::LENGTH_COUNT + BinaryFile::LENGTH_COUNT )); - } elseif (strlen($header[1]) != BaseBinaryFile::LENGTH_POSITION) { + } elseif (strlen($header[1]) != BinaryFile::LENGTH_POSITION) { // Position length not valid throw new UnexpectedValueException(sprintf('header[2](%d)=%s is not expected %d length', strlen($header[1]), $header[1], - BaseBinaryFile::LENGTH_POSITION + BinaryFile::LENGTH_POSITION )); } @@ -178,19 +179,19 @@ abstract class BaseFileStack extends BaseStacker { StackableFile::STACK_MAGIC, // Separator magic<->count - chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), + chr(BinaryFile::SEPARATOR_HEADER_DATA), // Padded total entries - str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), + str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getCounter()), BinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT), // Separator count<->seek position - chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), + chr(BinaryFile::SEPARATOR_HEADER_DATA), // Padded seek position - str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT), + str_pad(StringUtils::dec2hex($this->getIteratorInstance()->getBinaryFileInstance()->getSeekPosition(), 2), BinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT), // Separator position<->entries - chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES) + chr(BinaryFile::SEPARATOR_HEADER_ENTRIES) ); // Write it to disk (header is always at seek position 0) @@ -230,11 +231,11 @@ abstract class BaseFileStack extends BaseStacker { // Calculate header size $headerSize = ( strlen(StackableFile::STACK_MAGIC) + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) + - BaseBinaryFile::LENGTH_COUNT + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) + - BaseBinaryFile::LENGTH_POSITION + - strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)) + strlen(chr(BinaryFile::SEPARATOR_HEADER_DATA)) + + BinaryFile::LENGTH_COUNT + + strlen(chr(BinaryFile::SEPARATOR_HEADER_DATA)) + + BinaryFile::LENGTH_POSITION + + strlen(chr(BinaryFile::SEPARATOR_HEADER_ENTRIES)) ); // Setting it @@ -533,11 +534,11 @@ abstract class BaseFileStack extends BaseStacker { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Calculating ...'); self::$minimumBlockLength = // Length of entry group - BaseBinaryFile::LENGTH_GROUP + strlen(chr(BaseBinaryFile::SEPARATOR_GROUP_HASH)) + + BinaryFile::LENGTH_GROUP + strlen(chr(BinaryFile::SEPARATOR_GROUP_HASH)) + // Hash + value - self::getHashLength() + strlen(chr(BaseBinaryFile::SEPARATOR_HASH_VALUE)) + 1 + + self::getHashLength() + strlen(chr(BinaryFile::SEPARATOR_HASH_VALUE)) + 1 + // Final separator - strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES)); + strlen(chr(BinaryFile::SEPARATOR_ENTRIES)); } // Return it @@ -700,9 +701,9 @@ abstract class BaseFileStack extends BaseStacker { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: stackName=%s,hash=%s,encoded()=%d - CALLED!', $stackName, $hash, strlen($encoded))); $rawData = sprintf('%s%s%s%s%s', $stackName, - BaseBinaryFile::SEPARATOR_GROUP_HASH, + BinaryFile::SEPARATOR_GROUP_HASH, hex2bin($hash), - BaseBinaryFile::SEPARATOR_HASH_VALUE, + BinaryFile::SEPARATOR_HASH_VALUE, $encoded );