Ejemplo n.º 1
0
 /**
  * Object constructor.
  *
  * Verifies that the data source has been properly initialized.
  *
  * @param \ZendPdf\BinaryParser\DataSource\AbstractDataSource $dataSource
  * @throws \ZendPdf\Exception\ExceptionInterface
  */
 public function __construct(DataSource\AbstractDataSource $dataSource)
 {
     if ($dataSource->getSize() == 0) {
         throw new Exception\BinaryParserException('The data source has not been properly initialized');
     }
     $this->_dataSource = $dataSource;
 }
Ejemplo n.º 2
0
 /**
  * Reads the Pascal string from the binary file at the current byte offset.
  *
  * The length of the Pascal string is determined by reading the length bytes
  * which preceed the character data. You must supply the desired resulting
  * character set.
  *
  * Advances the offset by the number of bytes read. Throws an exception if
  * an error occurs.
  *
  * @param string $characterSet (optional) Desired resulting character set.
  *   You may use any character set supported by {@link iconv()}. If omitted,
  *   uses 'current locale'.
  * @param integer $lengthBytes (optional) Number of bytes that make up the
  *   length. Default is 1.
  * @return string
  * @throws \ZendPdf\Exception\ExceptionInterface
  */
 public function readStringPascal($characterSet = '', $lengthBytes = 1)
 {
     $byteCount = $this->readUInt($lengthBytes);
     if ($byteCount == 0) {
         return '';
     }
     $bytes = $this->_dataSource->readBytes($byteCount);
     if ($characterSet == 'ASCII') {
         return $bytes;
     }
     return iconv('ASCII', $characterSet, $bytes);
 }
Ejemplo n.º 3
0
 /**
  * Seeks the file read position to the specified byte offset.
  *
  * Throws an exception if the file pointer cannot be moved or if it is
  * moved beyond EOF (end of file).
  *
  * @param integer $offset Destination byte offset.
  * @throws \ZendPdf\Exception\ExceptionInterface
  */
 public function moveToOffset($offset)
 {
     if ($this->_offset == $offset) {
         return;
         // Not moving; do nothing.
     }
     parent::moveToOffset($offset);
     $result = @fseek($this->_fileResource, $offset, SEEK_SET);
     if ($result !== 0) {
         throw new Exception\IOException('Error while setting new file position');
     }
     if (feof($this->_fileResource)) {
         throw new Exception\IOException('Moved beyond the end of the file');
     }
 }