Horde_ActiveSync_Wbxml_Decoder::_getOpaque PHP Method

_getOpaque() protected method

Get an opaque value from the stream of the specified length.
protected _getOpaque ( integer $len ) : string
$len integer The length of the data to fetch.
return string A string of bytes representing the opaque value.
    protected function _getOpaque($len)
    {
        // See http://php.net/fread for why we can't simply use a single fread()
        // here. Bottom line, for buffered network streams it may be possible
        // that fread will only return a portion of the stream if chunk
        // is smaller then $len, so we use a loop to reach $len.
        $d = '';
        while (1) {
            $l = $len - strlen($d) > 8192 ? 8192 : $len - strlen($d);
            if ($l > 0) {
                $data = $this->_stream->substring(0, $l);
                // Stream ends prematurely on instable connections and big mails
                if ($data === false || $this->_stream->eof()) {
                    throw new Horde_ActiveSync_Exception(sprintf('Connection unavailable while trying to read %d bytes from stream. Aborting after %d bytes read.', $len, strlen($d)));
                } else {
                    $d .= $data;
                }
            }
            if (strlen($d) >= $len) {
                break;
            }
        }
        return $d;
    }