public function appending() { with($stream = new FileOutputStream($this->file, true)); $stream->write('!'); $this->file->close(); $this->assertEquals('Created by FileOutputStreamTest!', FileUtil::getContents($this->file)); }
public function get_contents_read_returns_less_than_size() { $f = new File(Streams::readableFd(newinstance(MemoryInputStream::class, ['Test'], ['read' => function ($size = 4096) { return parent::read(min(1, $size)); }]))); $this->assertEquals('Test', FileUtil::getContents($f)); }
public function fetchWsdl() { if (0 == strncmp('https://', $this->uri, 8) || 0 == strncmp('http://', $this->uri, 7)) { return HttpUtil::get(new HttpConnection(new \peer\URL($this->uri))); } else { return \io\FileUtil::getContents(new File($this->uri)); } }
/** * Retrieve contents of errordocument * * @return string content */ public function getContent() { try { $contents = FileUtil::getContents(new File($this->filename)); } catch (\Exception $e) { $this->message .= $e->toString(); $contents = '<xp:value-of select="reason"/>'; } return str_replace('<xp:value-of select="reason"/>', $this->message, $contents); }
public function get_contents_read_returns_less_than_size() { $data = 'Test'; $f = newinstance('io.Stream', array(), '{ public function read($size= 4096) { return parent::read(min(1, $size)); } }'); $f->open(STREAM_MODE_WRITE); $f->write($data); $f->close(); $this->assertEquals($data, FileUtil::getContents($f)); }
/** * Add a file * * @param string id the id under which this entry will be located * @param io.File file */ public function addFile($id, $file) { $bytes = FileUtil::getContents($file); $this->_index[$id] = [strlen($bytes), -1, $bytes]; }
public function write_bc() { $s = new \io\Stream(); $this->image->saveTo(new JpegStreamWriter(ref($s))); $this->assertNotEmpty(\io\FileUtil::getContents($s)); }
public function load_existing_resource_stream_from_archive() { $contents = FileUtil::getContents($this->fixture->getResourceAsStream('test/package-info.xp')); $this->assertEquals('<?php', substr($contents, 0, strpos($contents, "\n"))); }
/** * Create a new checksum from a file object * * @param io.File file * @param string key default NULL * @return self */ public static function fromFile($file, $key = null) { return new self(self::hash(FileUtil::getContents($file), $key)); }
/** * Fetch data * * @param string name * @return string data */ protected function fetch($name) { return FileUtil::getContents(new File($this->path, $name)); }
public function loadingNonexistantFile() { $this->assertEquals('Foobar', trim(FileUtil::getContents(new File('res://one/Dummy.txt')))); }
/** * Create a new checksum from a file object * * @param io.File file * @return security.checksum.CRC32 */ public static function fromFile($file) { return self::fromString(FileUtil::getContents($file)); }
/** * Load an image * * @param peer.URL source * @return string[2] data and contenttype */ public function load($source) { return [FileUtil::getContents(new File($source->getURL())), MimeType::getByFilename($source->getURL())]; }
/** * Construct an XML tree from a file. * * <code> * $tree= Tree::fromFile(new File('foo.xml')); * </code> * * @param io.File file * @param string c default __CLASS__ class name * @return xml.Tree * @throws xml.XMLFormatException in case of a parser error * @throws io.IOException in case reading the file fails */ public static function fromFile($file, $c = __CLASS__) { $parser = new XMLParser(); $tree = new $c(); $parser->setCallback($tree); $parser->parse(FileUtil::getContents($file)); // Fetch actual encoding from parser $tree->setEncoding($parser->getEncoding()); unset($parser); return $tree; }