setReadPointer() public method

Move the internal read pointer to $byteOffset in the stream.
public setReadPointer ( integer $byteOffset ) : boolean
$byteOffset integer
return boolean
 /**
  * Merges an OutputByteStream to Swift_Message.
  *
  * @param Swift_OutputByteStream $fromStream
  * @param Swift_Message          $message
  */
 protected function streamToMime(Swift_OutputByteStream $fromStream, Swift_Message $message)
 {
     $bufferLength = 78;
     $headerData = '';
     $fromStream->setReadPointer(0);
     while (($buffer = $fromStream->read($bufferLength)) !== false) {
         $headerData .= $buffer;
         if (false !== strpos($buffer, "\r\n\r\n")) {
             break;
         }
     }
     $headersPosEnd = strpos($headerData, "\r\n\r\n");
     $headerData = trim($headerData);
     $headerData = substr($headerData, 0, $headersPosEnd);
     $headerLines = explode("\r\n", $headerData);
     unset($headerData);
     $headers = array();
     $currentHeaderName = '';
     foreach ($headerLines as $headerLine) {
         // Line separated
         if (ctype_space($headerLines[0]) || false === strpos($headerLine, ':')) {
             $headers[$currentHeaderName] .= ' ' . trim($headerLine);
             continue;
         }
         $header = explode(':', $headerLine, 2);
         $currentHeaderName = strtolower($header[0]);
         $headers[$currentHeaderName] = trim($header[1]);
     }
     $messageStream = new Swift_ByteStream_TemporaryFileByteStream();
     $messageStream->addFilter($this->replacementFactory->createFilter("\r\n", "\n"), 'CRLF to LF');
     $messageStream->addFilter($this->replacementFactory->createFilter("\n", "\r\n"), 'LF to CRLF');
     $messageHeaders = $message->getHeaders();
     // No need to check for 'application/pkcs7-mime', as this is always base64
     if ('multipart/signed;' === substr($headers['content-type'], 0, 17)) {
         if (!preg_match('/boundary=("[^"]+"|(?:[^\\s]+|$))/is', $headers['content-type'], $contentTypeData)) {
             throw new Swift_SwiftException('Failed to find Boundary parameter');
         }
         $boundary = trim($contentTypeData['1'], '"');
         $boundaryLen = strlen($boundary);
         // Skip the header and CRLF CRLF
         $fromStream->setReadPointer($headersPosEnd + 4);
         while (false !== ($buffer = $fromStream->read($bufferLength))) {
             $messageStream->write($buffer);
         }
         $messageStream->commit();
         $messageHeaders->remove('Content-Transfer-Encoding');
         $message->setContentType($headers['content-type']);
         $message->setBoundary($boundary);
         $message->setBody($messageStream);
     } else {
         $fromStream->setReadPointer($headersPosEnd + 4);
         if (null === $this->headerFactory) {
             $this->headerFactory = Swift_DependencyContainer::getInstance()->lookup('mime.headerfactory');
         }
         $message->setContentType($headers['content-type']);
         $messageHeaders->set($this->headerFactory->createTextHeader('Content-Transfer-Encoding', $headers['content-transfer-encoding']));
         $messageHeaders->set($this->headerFactory->createTextHeader('Content-Disposition', $headers['content-disposition']));
         while (false !== ($buffer = $fromStream->read($bufferLength))) {
             $messageStream->write($buffer);
         }
         $messageStream->commit();
         $message->setBody($messageStream);
     }
 }
示例#2
0
 /**
  * @see Swift_CharacterStream::importByteStream()
  *
  * @param Swift_OutputByteStream $os
  */
 public function importByteStream(Swift_OutputByteStream $os)
 {
     $this->flushContents();
     $blocks = 512;
     $os->setReadPointer(0);
     while (false !== ($read = $os->read($blocks))) {
         $this->write($read);
     }
 }
 private function _readStream(Swift_OutputByteStream $os)
 {
     $string = '';
     while (false !== ($bytes = $os->read(8192))) {
         $string .= $bytes;
     }
     $os->setReadPointer(0);
     return $string;
 }