Swift_CharacterStream_ArrayCharacterStream::readBytes PHP Method

readBytes() public method

Read $length characters from the stream and return a 1-dimensional array containing there octet values.
public readBytes ( integer $length ) : integer[]
$length integer
return integer[]
    public function readBytes($length)
    {
        if ($this->_offset == $this->_array_size) {
            return false;
        }
        $arrays = array();
        $end = $length + $this->_offset;
        for ($i = $this->_offset; $i < $end; ++$i) {
            if (!isset($this->_array[$i])) {
                break;
            }
            $arrays[] = $this->_array[$i];
        }
        $this->_offset += $i - $this->_offset;
        // Limit function calls
        return call_user_func_array('array_merge', $arrays);
    }

Usage Example

 public function testRequestingByteArrayCountPastEndOfStream()
 {
     $reader = $this->_getReader();
     $factory = $this->_getFactory($reader);
     $stream = new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8');
     $seq = $this->_mockery()->sequence('read-sequence');
     $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->importString(pack('C*', 0xd0, 0x94, 0xd0, 0xb6, 0xd0, 0xbe));
     $this->assertEqual(array(0xd0, 0x94, 0xd0, 0xb6, 0xd0, 0xbe), $stream->readBytes(100));
     $this->assertIdentical(false, $stream->readBytes(1));
 }
All Usage Examples Of Swift_CharacterStream_ArrayCharacterStream::readBytes