getInitialByteSize() public method

For fixed width character sets this should be the number of octets-per-character. For multibyte character sets this will probably be 1.
public getInitialByteSize ( ) : integer
return integer
コード例 #1
0
  /**
   * Write $chars to the end of the stream.
   * @param string $chars
   */
  public function write($chars)
  {
    if (!isset($this->_charReader))
    {
      $this->_charReader = $this->_charReaderFactory->getReaderFor(
        $this->_charset);
    }

    $startLength = $this->_charReader->getInitialByteSize();

    $fp = fopen('php://memory', 'w+b');
    fwrite($fp, $chars);
    unset($chars);
    fseek($fp, 0, SEEK_SET);

    $buffer = array(0);
    $buf_pos = 1;
    $buf_len = 1;
    $has_datas = true;
    do
    {
      $bytes = array();
      // Buffer Filing
      if ($buf_len - $buf_pos < $startLength)
      {
        $buf = array_splice($buffer, $buf_pos);
        $new = $this->_reloadBuffer($fp, 100);
        if ($new)
        {
          $buffer = array_merge($buf, $new);
          $buf_len = count($buffer);
          $buf_pos = 0;
        }
        else
        {
          $has_datas = false;
        }
      }
      if ($buf_len - $buf_pos > 0)
      {
        $size = 0;
        for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i)
        {
          ++$size;
          $bytes[] = $buffer[$buf_pos++];
        }
        $need = $this->_charReader->validateByteSequence(
          $bytes, $size);
        if ($need > 0)
        {
          if ($buf_len - $buf_pos < $need)
          {
            $new = $this->_reloadBuffer($fp, $need);
            
            if ($new)
            {
              $buffer = array_merge($buffer, $new);
              $buf_len = count($buffer);
            }
          }
          for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i)
          {
            $bytes[] = $buffer[$buf_pos++];
          }
        }
        $this->_array[] = $bytes;
        ++$this->_array_size;
      }
    }
    while ($has_datas);
    
    fclose($fp);
  }