Initialize the internal stream for writing.

@see StreamWrapper::stream_open()
@return boolean
511457
private function initWritableStream()
    {
        $context = stream_context_get_options($this->context);

        $this->stream = new WritableStream(
            $context[$this->protocol]['collectionWrapper'],
            $context[$this->protocol]['filename'],
            $context[$this->protocol]['options']
        );

        return true;
    }
1367549
private function setStream(): InputFile
    {
        if (is_readable($this->path)) {
            $this->stream = fopen($this->path, 'rb');
        } else {
            throw new FileNotReadable(sprintf('Can not read local file "%s", please check', $this->path));
        }

        return $this;
    }
656851
public function openAsync()
    {
        return $this->readBeforeStream()
        ->otherwise(function($err) {
            //If failed to load initial portion of tweets, continue anyway
            $this->emit("warning", [$err]);
        })
        ->then(function($initialTweets) {
            $this->emit("clear_tweets", []);
            foreach ($initialTweets as $tweet) {
              $this->emit("tweet", [$tweet]);
            }
            return $this->openStream();
        });
    }
1322929
public function stream_flush()
    {
        if (!$this->getResource()) {
            return false;
        }

        $buffer = $this->getDataBuffer();
        $bufferWritten = $buffer;
        $retVal = true;
        if (!empty($buffer)) {

            $object = $this->getResource()->getObject();
            $mimetype = $this->getService()->guessFileType($this->getResource()->getResourceName());
            $object->content_type = $mimetype;
            $object->setData($buffer);
            $object->Create();
        }

       if (strlen($bufferWritten) ==  strlen($buffer)) {
            $this->setDataBuffer(null);
        } else {
            $this->setDataBuffer($buffer);
        }
        $this->setDataBuffer(null);

        return $retVal;
    }
716842
public function stream_open($path, $mode, $options, &$openedPath)
    {
        $container = $this->getContainerFromContext($path);
        $path = $this->stripScheme($path);

        $mode = str_split(str_replace('b', '', $mode));

        $accessDeniedError = function () use ($path, $options) {
            if ($options & STREAM_REPORT_ERRORS) {
                trigger_error(sprintf('fopen(%s): failed to open stream: Permission denied', $path), E_USER_WARNING);
            }

            return false;
        };

        $appendMode = in_array('a', $mode);
        $readMode = in_array('r', $mode);
        $writeMode = in_array('w', $mode);
        $extended = in_array('+', $mode);

        if (!$container->hasNodeAt($path)) {
            if ($readMode || !$container->hasNodeAt(dirname($path))) {
                if ($options & STREAM_REPORT_ERRORS) {
                    trigger_error(sprintf('%s: failed to open stream.', $path), E_USER_WARNING);
                }

                return false;
            }
            $parent = $container->directoryAt(dirname($path));
            $permissionHelper = $container->getPermissionHelper($parent);
            if (!$permissionHelper->isWritable()) {
                return $accessDeniedError();
            }
            $parent->addFile($container->factory()->getFile(basename($path)));
        }

        $file = $container->nodeAt($path);

        if ($file instanceof Link) {
            $file = $file->getDestination();
        }

        if (($extended || $writeMode || $appendMode) && $file instanceof Directory) {
            if ($options & STREAM_REPORT_ERRORS) {
                trigger_error(sprintf('fopen(%s): failed to open stream: Is a directory', $path), E_USER_WARNING);
            }

            return false;
        }

        if ($file instanceof Directory) {
            $dir = $file;
            $file = $container->factory()->getFile('tmp');
            $file->chmod($dir->mode());
            $file->chown($dir->user());
            $file->chgrp($dir->group());
        }

        $permissionHelper = $container->getPermissionHelper($file);

        $this->currentlyOpenedFile = new FileHandler();
        $this->currentlyOpenedFile->setFile($file);

        if ($extended) {
            if (!$permissionHelper->isReadable() || !$permissionHelper->isWritable()) {
                return $accessDeniedError();
            }
            $this->currentlyOpenedFile->setReadWriteMode();
        } elseif ($readMode) {
            if (!$permissionHelper->isReadable()) {
                return $accessDeniedError();
            }
            $this->currentlyOpenedFile->setReadOnlyMode();
        } else { // a or w are for write only
            if (!$permissionHelper->isWritable()) {
                return $accessDeniedError();
            }
            $this->currentlyOpenedFile->setWriteOnlyMode();
        }

        if ($appendMode) {
            $this->currentlyOpenedFile->seekToEnd();
        } elseif ($writeMode) {
            $this->currentlyOpenedFile->truncate();
            clearstatcache();
        }

        $openedPath = $file->path();

        return true;
    }
468640
public void openReadWrite(ReadStreamOld is, WriteStreamOld os) throws IOException
  {
    clearStatusCache();

    StreamImpl impl = openReadWriteImpl();
    //impl.setPath(this);

    os.init(impl);
    is.init(impl);
  }
37019
public function open()
    {

        $this->log('open socket connection');
        $this->socket = @stream_socket_client($this->remote_socket,  $errno, $errstr, $this->timeout);

        if ($this->socket) {

            return true;
        } else {
            throw(new \Exception("{$errstr} (#{$errno})"));
        }
    }
293501
private function createStreamCallback()
    {
        $this->streamCallback = function ($stream, $flags) {
            $key = (int) $stream;

            if (EV_READ === (EV_READ & $flags) && isset($this->readListeners[$key])) {
                call_user_func($this->readListeners[$key], $stream, $this);
            }

            if (EV_WRITE === (EV_WRITE & $flags) && isset($this->writeListeners[$key])) {
                call_user_func($this->writeListeners[$key], $stream, $this);
            }
        };
    }
799190
private function createStreamCallback()
    {
        $read =& $this->readListeners;
        $write =& $this->writeListeners;
        $this->streamCallback = function ($stream, $flags) use (&$read, &$write) {
            $key = (int) $stream;

            if (Event::READ === (Event::READ & $flags) && isset($read[$key])) {
                \call_user_func($read[$key], $stream);
            }

            if (Event::WRITE === (Event::WRITE & $flags) && isset($write[$key])) {
                \call_user_func($write[$key], $stream);
            }
        };
    }
54066
public function initialize()
    {
        if ($this->isActive()) {
            throw new RuntimeException('Process is already active');
        }

        $handle = $this->getFileResource();

        if (! @flock($handle, (LOCK_EX | LOCK_NB))) {
            throw new RuntimeException('Could not lock pidfile');
        }

        if (-1 === @fseek($handle, 0)) {
            throw new RuntimeException('Could not seek pidfile cursor');
        }

        if (! @ftruncate($handle, 0)) {
            throw new RuntimeException('Could not truncate pidfile');
        }

        if (! @fwrite($handle, $this->control->info()->getId().PHP_EOL)) {
            throw new RuntimeException('Could not write on pidfile');
        }
    }
938002
protected function localFileStream() {

    $tmp = fopen('php://temp', 'rw');
    fwrite($tmp, $this->content(), $this->contentLength());
    rewind($tmp);

    return $tmp;
  }
110070
protected function _buildFOpenStreamContext()
    {
        # Set the headers required to work with fopen
        $headers =  $this->_generateProxyRequestHeaders(TRUE);
        $headers.= 'Cookie: ' . $this->_buildProxyRequestCookieString();

        # Create the stream context
        $stream_context = array (
            'header'        => $headers,
            'user_agent'    => $this->_requestUserAgent
        );

        # Figure out what kind of request we're making, and what to fill it with
        $stream_context['method'] = $this->_requestMethod;

        if($this->_requestMethod === 'POST' ||
           $this->_requestMethod === 'PUT')
        {
            $stream_context['content'] = $this->_requestBody;
        }

        return stream_context_create(array('http' => $stream_context));
    }
354530
public function OpenWriter() {
        $filePath = $this->dir . $this->fileName;
        echo $filePath . "<br />";

//    if(!file_exists($filePath)) {
//      file_put_contents($filePath, "");
//    }
        $this->writer = fopen($filePath, 'w') or die("can't open file");
    }
503142
public function setStream($stream = null)
    {
        // String passed in? Try converting it to a stream
        if (is_string($stream)) {
            $stream = @fopen($stream, 'a');
        }

        // Make sure the stream is a resource
        if (!is_resource($stream)) {
            throw new \InvalidArgumentException('Invalid Stream');
        }

        // Store it
        $this->stream = $stream;

        // Afford chaining
        return $this;
    }
604113
private function createStreamCallback()
    {
        $this->streamCallback = function ($stream, $flags) {
            $key = (int) $stream;

            if (Event::READ === (Event::READ & $flags) && isset($this->readListeners[$key])) {
                call_user_func($this->readListeners[$key], $stream, $this);
            }

            if (Event::WRITE === (Event::WRITE & $flags) && isset($this->writeListeners[$key])) {
                call_user_func($this->writeListeners[$key], $stream, $this);
            }
        };
    }
1227747
public function initializeStreamWrapper()
    {
        $stream = new Stream('accompli', array(
                'recipe' => realpath(__DIR__.'/Resources/recipe'),
            ), false);

        StreamManager::create()->registerStream($stream);
    }
1220609
public function stream_tell()
    {
        if ($this->fileHandle === null) {
            return false;
        }
        self::restore();
        $position = ftell($this->fileHandle);
        self::register();
        return $position;
    }