Swift_CharacterStream_ArrayCharacterStream::importByteStream PHP Method

importByteStream() public method

Overwrite this character stream using the byte sequence in the byte stream.
public importByteStream ( Swift_OutputByteStream $os )
$os Swift_OutputByteStream output stream to read from
    public function importByteStream(Swift_OutputByteStream $os)
    {
        if (!isset($this->_charReader)) {
            $this->_charReader = $this->_charReaderFactory->getReaderFor($this->_charset);
        }
        $startLength = $this->_charReader->getInitialByteSize();
        while (false !== ($bytes = $os->read($startLength))) {
            $c = array();
            for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
                $c[] = self::$_byteMap[$bytes[$i]];
            }
            $size = count($c);
            $need = $this->_charReader->validateByteSequence($c, $size);
            if ($need > 0 && false !== ($bytes = $os->read($need))) {
                for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
                    $c[] = self::$_byteMap[$bytes[$i]];
                }
            }
            $this->_array[] = $c;
            ++$this->_array_size;
        }
    }

Usage Example

 public function testImportingStreamProducesCorrectCharArray()
 {
     $reader = $this->_getReader();
     $factory = $this->_getFactory($reader);
     $os = $this->_getByteStream();
     $stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
     $seq = $this->_mockery()->sequence('read-stream');
     $this->_checking(Expectations::create()->between(0, 1)->of($os)->setReadPointer(0)->one($os)->read(any())->inSequence($seq)->returns(pack('C*', 0xd0))->one($os)->read(any())->inSequence($seq)->returns(pack('C*', 0x94))->one($os)->read(any())->inSequence($seq)->returns(pack('C*', 0xd0))->one($os)->read(any())->inSequence($seq)->returns(pack('C*', 0xb6))->one($os)->read(any())->inSequence($seq)->returns(pack('C*', 0xd0))->one($os)->read(any())->inSequence($seq)->returns(pack('C*', 0xbe))->ignoring($os)->read(any())->returns(false));
     $seq = $this->_mockery()->sequence('read-chars');
     $this->_checking(Expectations::create()->ignoring($reader)->getInitialByteSize()->returns(1)->one($reader)->validateByteSequence(array(0xd0), 1)->inSequence($seq)->returns(1)->one($reader)->validateByteSequence(array(0xd0), 1)->inSequence($seq)->returns(1)->one($reader)->validateByteSequence(array(0xd0), 1)->inSequence($seq)->returns(1));
     $stream->importByteStream($os);
     $this->assertIdenticalBinary(pack('C*', 0xd0, 0x94), $stream->read(1));
     $this->assertIdenticalBinary(pack('C*', 0xd0, 0xb6), $stream->read(1));
     $this->assertIdenticalBinary(pack('C*', 0xd0, 0xbe), $stream->read(1));
     $this->assertIdentical(false, $stream->read(1));
 }
All Usage Examples Of Swift_CharacterStream_ArrayCharacterStream::importByteStream