public function write($string, $length = null)
    {
        $this->assertWritable();
        if (null === $length) {
            $ret = fwrite($this->stream, $string);
        } else {
            $ret = fwrite($this->stream, $string, $length);
        }
        if (false === $ret) {
            throw new RuntimeException('Cannot write on stream');
        }

        return $ret;
    }