Opens a calendar stream, if it has not already been
opened. This is implicitly called by log(), if necessary.
@access public
351459
function open()
    {
        if (!$this->_opened) {
            $this->_stream = mcal_open($this->_calendar, $this->_username,
                $this->_password, $this->_options);
            $this->_opened = true;
        }

        return $this->_opened;
    }
946805
public function stream()
    {
        if (ob_get_level()) {
            ob_end_clean();
        }

        // Transfer file in 1024 byte chunks to save memory usage.
        if ($fd = fopen($this->path, 'rb')) {
            while (!feof($fd)) {
                echo fread($fd, 1024);
            }
            fclose($fd);
        }
    }
1213393
def start_event_stream(self):
        
        if not self._stream:
            self._stream = GerritStream(self, ssh_client=self._ssh_client)
            self._stream.start()
503798
public function open()
  {
    if ($this->isOpen()) {
      throw new TTransportException('Socket already connected', TTransportException::ALREADY_OPEN);
    }

    if (empty($this->host_)) {
      throw new TTransportException('Cannot open null host', TTransportException::NOT_OPEN);
    }

    if ($this->port_ <= 0) {
      throw new TTransportException('Cannot open without port', TTransportException::NOT_OPEN);
    }

    if ($this->persist_) {
      $this->handle_ = @pfsockopen($this->host_,
                                   $this->port_,
                                   $errno,
                                   $errstr,
                                   $this->sendTimeoutSec_ + ($this->sendTimeoutUsec_ / 1000000));
    } else {
      $this->handle_ = @fsockopen($this->host_,
                                  $this->port_,
                                  $errno,
                                  $errstr,
                                  $this->sendTimeoutSec_ + ($this->sendTimeoutUsec_ / 1000000));
    }

    // Connect failed?
    if ($this->handle_ === FALSE) {
      $error = 'TSocket: Could not connect to '.$this->host_.':'.$this->port_.' ('.$errstr.' ['.$errno.'])';
      if ($this->debug_) {
        call_user_func($this->debugHandler_, $error);
      }
      throw new TException($error);
    }
  }
8959
protected function attemptStreamRecovery()
    {
        if ('resource' === gettype($this->stream))
        {
            @fflush($this->stream);
            @fclose($this->stream);
        }

        $this->stream = fopen($this->streamURI, $this->streamMode);
        if (false === $this->stream)
        {
            trigger_error(sprintf(
                '%s - Unable to write to "%s" and re-open attempt failed, will default to php-output',
                get_called_class(),
                $this->streamURI));

            $this->stream = $this->defaultStream();
        }
    }
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);
            }
        };
    }
212391
public function main()
    {
        try {
            $lock = new FileLock('import_' . md5(__FILE__) . '.lock');
        } catch (Exception $e) {
            $this->abort($e->getMessage());

            // Rethrow the exception if some reason we have reached this point
            // This shouldn't happen since `$this->abort` throw another Exception
            throw $e;
        }

        if (!$lock->lock()) {
            $this->abort('Import is already in progress');
        }

        /** @var \Qobo\Calendar\Model\Table\CalendarAttendeesTable $table */
        $table = TableRegistry::get('Qobo/Calendar.CalendarAttendees');
        $this->attendeesTable = $table;

        /** @var \Qobo\Calendar\Model\Table\CalendarsTable $table */
        $table = TableRegistry::get('Qobo/Calendar.Calendars');
        $this->calendarsTable = $table;

        /** @var \CakeDC\Users\Model\Table\UsersTable $table */
        $table = $this->getUsersTable();
        $this->usersTable = $table;

        $calendarsProcessed = 1;
        $output = $result = $options = [];

        /** @var \Cake\Shell\Helper\ProgressHelper $progress */
        $progress = $this->helper('Progress');
        $progress->init();

        $this->info('Preparing for calendar sync...');

        $options = $this->setDefaultTimePeriod($this->params);

        $result['calendars'] = $this->calendarsTable->syncCalendars($options);

        if (empty($result['calendars'])) {
            $this->abort('No calendars found for synchronization');
        }

        foreach ($result['calendars'] as $actionName => $calendars) {
            foreach ($calendars as $k => $calendar) {
                $resultEvents = $this->calendarsTable->syncCalendarEvents($calendar, $options);

                $resultAttendees = $this->calendarsTable->syncEventsAttendees($calendar, $resultEvents);

                $output[] = [
                    'action' => $actionName,
                    'calendar' => $calendar,
                    'events' => $resultEvents,
                    'attendees' => $resultAttendees,
                ];

                $progress->increment(100 / ++$calendarsProcessed);
                $progress->draw();
            }
        }

        $this->syncAttendees();
        $birthdays = $this->syncBirthdays($this->calendarsTable);

        $this->out(null);
        $this->success('Synchronization complete!');
        $this->out(null);

        if (true == $this->params['verbose']) {
            print_r($output);
        }

        $lock->unlock();
    }
93697
public function stream()
    {
        $stream = fopen($this->file, 'r');

        $stream = $stream === false ? null : $stream;

        return new Stream($stream);
    }
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);
            }
        };
    }
1100110
function open() {
        // let's try to open a socket
        $this->_error_log('open a socket connection');
        $this->sock = fsockopen($this->_socket . $this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);
        core_php_time_limit::raise(30);
        if (is_resource($this->sock)) {
            socket_set_blocking($this->sock, true);
            $this->_connection_closed = false;
            $this->_error_log('socket is open: ' . $this->sock);
            return true;
        } else {
            $this->_error_log("$this->_errstr ($this->_errno)\n");
            return false;
        }
    }
146886
protected function _openTempStream()
    {
        $this->_stream_name = $this->config['output_stream'];
        if(!is_string($this->_stream_name)) {
            // If name is not given, create temp name
            $this->_stream_name = tempnam(isset($this->config['stream_tmp_dir'])?$this->config['stream_tmp_dir']:sys_get_temp_dir(),
                 'Zend_Http_Client');
        }

        if (false === ($fp = @fopen($this->_stream_name, "w+b"))) {
                if ($this->adapter instanceof Zend_Http_Client_Adapter_Interface) {
                    $this->adapter->close();
                }

                throw new Zend_Http_Client_Exception("Could not open temp file {$this->_stream_name}");
        }

        return $fp;
    }
379213
private void processCalendars() throws IOException
   {
      CalendarReader reader = new CalendarReader(m_data.getTableData("Calendars"));
      reader.read();

      for (MapRow row : reader.getRows())
      {
         processCalendar(row);
      }

      m_project.setDefaultCalendar(m_calendarMap.get(reader.getDefaultCalendarUUID()));
   }
218446
function returnCalendar() {
    $filename = $this->getConfig( 'filename' );
    $output   = $this->createCalendar();
    $filesize = strlen( $output );
//    if( headers_sent( $filename, $linenum ))
//      die( "Headers already sent in $filename on line $linenum\n" );
    if( 'xcal' == $this->format )
      header( 'Content-Type: application/calendar+xml; charset=utf-8' );
    else
      header( 'Content-Type: text/calendar; charset=utf-8' );
    header( 'Content-Length: '.$filesize );
    header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
    header( 'Cache-Control: max-age=10' );
    echo $output;
    die();
  }
158619
public function stream_open($path, $mode, $options, &$opened_path)
    {
        if ($this->fileHandle !== null) {
            return false;
        }
        self::restore();
        $path = self::overlayPath($path);
        $this->fileHandle = fopen($path, $mode, (bool)($options & STREAM_USE_PATH));
        self::register();
        return $this->fileHandle !== false;
    }
199341
protected function open_log_file() {

        if ($this->log_file) {

            if ($this->log_file_handle) {
                fclose($this->log_file_handle);
            }

            $this->log_file_handle = @fopen($this->config['log_file'], "a");
            if (!$this->log_file_handle) {
                $this->show_help("Could not open log file {$this->config['log_file']}");
            }
        }

    }
350776
public function init()
    {
        $stream = @fopen($this->config['url'], 'a');
        if (!$stream) {
            throw new \RuntimeException(sprintf("Couldn't open resource '%s'", $this->config['url']));
        }

        $this->stream = $stream;

        if (!empty($this->config['lock']) && $this->config['lock'] === true && stream_supports_lock($this->stream)) {
            $this->useLocks = true;
        }
    }
673522
function close()
    {
        if ($this->_opened) {
            mcal_close($this->_stream);
            $this->_opened = false;
        }

        return ($this->_opened === false);
    }