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 appending() { with($stream = new FileOutputStream($this->file, true)); $stream->write('!'); $this->file->close(); $this->assertEquals('Created by FileOutputStreamTest!', FileUtil::getContents($this->file)); }
public function setUp() { $tempDir = realpath(System::tempDir()); $this->fixture = new FilesystemPropertySource($tempDir); // Create a temporary ini file $this->tempFile = new File($tempDir, 'temp.ini'); FileUtil::setContents($this->tempFile, "[section]\nkey=value\n"); }
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)); } }
public static function createFiles() { self::$temp = new Folder(System::tempDir(), uniqid(microtime(true))); self::$temp->create(); $partials = new Folder(self::$temp, 'partials'); $partials->create(); FileUtil::setContents(new File(self::$temp, 'test.mustache'), 'Mustache template {{id}}'); FileUtil::setContents(new File($partials, 'navigation.mustache'), '{{#if nav}}nav{{/if}}'); }
/** * Sets up test case - creates temporary file * */ public function setUp() { try { $this->file = new TempFile(); FileUtil::setContents($this->file, 'Created by FileInputStreamTest'); } catch (\io\IOException $e) { throw new \unittest\PrerequisitesNotMetError('Cannot write temporary file', $e, array($this->file)); } }
/** * 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)); }
/** * Execute action * * @return int */ public function perform() { $this->archive->open(Archive::READ); $args = $this->getArguments(); while ($entry = $this->archive->getEntry()) { if (!$this->_filter($entry, $args)) { continue; } $f = new File($entry); $data = $this->archive->extract($entry); if (!($this->options & Options::SIMULATE)) { // Create folder on demand. Note that inside a XAR, the directory // separator is *ALWAYS* a forward slash, so we need to change // it to whatever the OS we're currently running on uses. $dir = new Folder(str_replace('/', DIRECTORY_SEPARATOR, dirname($entry))); if (!$dir->exists()) { $dir->create(); } FileUtil::setContents($f, $data); } $this->options & Options::VERBOSE && $this->out->writeLinef('%10s %s', number_format(strlen($data), 0, false, '.'), $entry); } $this->archive->close(); }
/** * Store data * * @param string name * @param string data */ protected function store($name, $data) { FileUtil::setContents(new File($this->path, $name), $data); }
public function read_bc() { $s = new Stream(); FileUtil::setContents($s, base64_decode('/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gNzUK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAAQABAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A9/ooooA//9k=')); Image::loadFrom(new \img\io\StreamReader(ref($s))); }
/** * 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)); }
public function readMalformedDataBC() { $s = new Stream(); FileUtil::setContents($s, '@@MALFORMED@@'); Image::loadFrom(new \img\io\StreamReader(ref($s))); }
public function write_bc() { $s = new \io\Stream(); $this->image->saveTo(new JpegStreamWriter(ref($s))); $this->assertNotEmpty(\io\FileUtil::getContents($s)); }
/** * Called when a test run finishes. * * @param unittest.TestSuite suite * @param unittest.TestResult result */ public function testRunFinished(\unittest\TestSuite $suite, TestResult $result) { $coverage = xdebug_get_code_coverage(); xdebug_stop_code_coverage(); $results = array(); foreach ($coverage as $fileName => $data) { foreach ($this->paths as $path) { if (substr($fileName, 0, strlen($path)) !== $path) { continue; } $results[dirname($fileName)][basename($fileName)] = $data; break; } } $pathsNode = new Node('paths'); foreach ($results as $pathName => $files) { $pathNode = new Node('path'); $pathNode->setAttribute('name', $pathName); foreach ($files as $fileName => $data) { $fileNode = new Node('file'); $fileNode->setAttribute('name', $fileName); $num = 1; $reader = new TextReader(new FileInputStream($pathName . '/' . $fileName)); while (($line = $reader->readLine()) !== null) { $lineNode = new Node('line', new CData($line)); if (isset($data[$num])) { if (1 === $data[$num]) { $lineNode->setAttribute('checked', 'checked'); } elseif (-1 === $data[$num]) { $lineNode->setAttribute('unchecked', 'unchecked'); } } $fileNode->addChild($lineNode); ++$num; } $pathNode->addChild($fileNode); } $pathsNode->addChild($pathNode); } $pathsNode->setAttribute('time', date('Y-m-d H:i:s')); $this->processor->setXMLBuf($pathsNode->getSource()); $this->processor->run(); FileUtil::setContents(new File($this->reportFile), $this->processor->output()); }
public function read_bc() { $s = new Stream(); FileUtil::setContents($s, base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAACklEQVQImWNgAAAAAgAB9HFkpgAAAABJRU5ErkJggg==')); Image::loadFrom(new \img\io\StreamReader(ref($s))); }
public function loadingNonexistantFile() { $this->assertEquals('Foobar', trim(FileUtil::getContents(new File('res://one/Dummy.txt')))); }
public function read_bc() { $s = new Stream(); FileUtil::setContents($s, base64_decode('R0lGODdhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=')); Image::loadFrom(new \img\io\StreamReader(ref($s))); }
/** * 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)); }
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"))); }
/** * 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; }
/** * Fetch data * * @param string name * @return string data */ protected function fetch($name) { return FileUtil::getContents(new File($this->path, $name)); }
/** * 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]; }
/** * 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())]; }