protected function ensureWritableHandle()
    {
        if ( ! $this->needsCowCheck) {
            return;
        }

        $this->needsCowCheck = false;

        if (StreamUtil::isWritable($this->handle)) {
            return;
        }

        $this->handle = StreamUtil::copy($this->handle);
    }