Exemple #1
0
 function close($client_id)
 {
     Stream::close($this->client_sock[$client_id]);
     $this->client_sock[$client_id] = null;
     unset($this->client_sock[$client_id]);
     $this->protocol->onClose($this, $client_id, 0);
 }
Exemple #2
0
 public function close()
 {
     if ($this->stream && is_resource($this->stream)) {
         fclose($this->stream);
     }
     parent::close();
 }
 public function get_contents()
 {
     $data = 'Test';
     $f = new Stream();
     $f->open(STREAM_MODE_WRITE);
     $f->write($data);
     $f->close();
     $this->assertEquals($data, FileUtil::getContents($f));
 }
 /**
  * Returns 
  *
  * @return  io.Stream
  */
 protected function archiveBytesAsStream($version = -1)
 {
     static $bytes = array(1 => "CCA", 2 => "CCA");
     $s = new Stream();
     $s->open(STREAM_WRITE);
     $s->write($bytes[$version < 0 ? $this->version() : $version]);
     $s->write(str_repeat("", 248));
     // Reserved bytes
     $s->close();
     return $s;
 }
Exemple #5
0
 /**
  * Closes this stream
  *
  * @return void
  */
 public function close()
 {
     $this->out->appendToken($this->out->format->close('}'));
     parent::close();
 }
Exemple #6
0
 /**
  * Write the stream to the given destionation directly without using extra memory like storing in an array etc.
  *
  * @param mixed $destination file path.
  */
 public function save($destination)
 {
     $dest = new Stream(is_resource($destination) ? $destination : fopen($destination, 'w+'));
     while (!$this->feof()) {
         $dest->write($this->read());
     }
     if (!is_resource($destination)) {
         // close the file if we opened it otwhise dont touch.
         $dest->close();
     }
 }
Exemple #7
0
 /**
  * 关闭某个客户端
  * @return unknown_type
  */
 function close($client_id)
 {
     Stream::close($this->client_sock[$client_id], $this->client_event[$client_id]);
     unset($this->client_sock[$client_id], $this->client_event[$client_id]);
     $this->protocol->onClose($this, $client_id, 0);
     $this->client_num--;
 }
 public function positionAfterReOpen()
 {
     $s = new Stream();
     $s->open(STREAM_MODE_WRITE);
     $s->write('GIF89a');
     $s->close();
     $s->open(STREAM_MODE_READ);
     $this->assertEquals(0, $s->tell());
     $this->assertEquals('GIF89a', $s->read());
     $s->close();
 }
 public function testReadline()
 {
     $stream = new Stream();
     $stream->open(STREAM_MODE_WRITE);
     $stream->writeLine('This is the first line.');
     $stream->writeLine('This is the second line.');
     $stream->writeLine('And there is a third one.');
     $stream->close();
     $stream->open(STREAM_MODE_READ);
     $this->s = new EncapsedStream($stream, 5, $stream->size() - 35);
     $this->assertEquals('is the first line.', $this->s->readLine());
     $this->assertEquals('This is the second li', $this->s->readLine());
     $this->assertEquals('', $this->s->readLine());
 }