8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * A wrapper for strings for buffered reading.
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
33 class Zend_Gdata_MimeBodyString
41 protected $_sourceString = '';
44 * The size of the MIME message.
47 protected $_bytesRead = 0;
50 * Create a new MimeBodyString object.
52 * @param string $sourceString The string we are wrapping.
54 public function __construct($sourceString)
56 $this->_sourceString
= $sourceString;
57 $this->_bytesRead
= 0;
61 * Read the next chunk of the string.
63 * @param integer $bytesRequested The size of the chunk that is to be read.
64 * @return string A corresponding piece of the string.
66 public function read($bytesRequested)
68 $len = strlen($this->_sourceString
);
69 if($this->_bytesRead
== $len) {
71 } else if($bytesRequested > $len - $this->_bytesRead
) {
72 $bytesRequested = $len - $this->_bytesRead
;
75 $buffer = substr($this->_sourceString
, $this->_bytesRead
, $bytesRequested);
76 $this->_bytesRead +
= $bytesRequested;
82 * The length of the string.
84 * @return int The length of the string contained in the object.
86 public function getSize()
88 return strlen($this->_sourceString
);