/**
  * Returns a DOM object for this response's contents. Lazy/Cached.
  *
  * @return  php.DOMDocument
  */
 public function getDom()
 {
     if (NULL === $this->dom) {
         $this->dom = new DOMDocument();
         @$this->dom->loadHTMLFile(Streams::readableUri($this->response->getInputStream()));
     }
     return $this->dom;
 }
 public function usableInLoad()
 {
     $dom = new \DOMDocument();
     $this->assertTrue($dom->load(Streams::readableUri(new MemoryInputStream(trim('
   <?xml version="1.0" encoding="utf-8"?>
   <root>
     <child>übercoder</child>
   </root>
 ')))));
     $this->assertEquals('übercoder', $dom->getElementsByTagName('child')->item(0)->nodeValue);
 }
 /**
  * Constructor
  *
  * @param   var stream either an io.streams.InputStream or an io.Stream (BC)
  * @throws  lang.IllegalArgumentException when types are not met
  */
 public function __construct($stream)
 {
     $this->stream = deref($stream);
     if ($this->stream instanceof InputStream) {
         if ($this instanceof img·io·UriReader && !self::$GD_USERSTREAMS_BUG) {
             $this->reader = function ($reader, $stream) {
                 return $reader->readImageFromUri(Streams::readableUri($stream));
             };
         } else {
             $this->reader = function ($reader, $stream) {
                 $bytes = '';
                 while ($stream->available() > 0) {
                     $bytes .= $stream->read();
                 }
                 $stream->close();
                 return $reader->readImageFromString($bytes);
             };
         }
     } else {
         if ($this->stream instanceof Stream) {
             if ($this instanceof img·io·UriReader && !self::$GD_USERSTREAMS_BUG) {
                 $this->reader = function ($reader, $stream) {
                     $stream->open(STREAM_MODE_READ);
                     return $reader->readImageFromUri($stream->getURI());
                 };
             } else {
                 $this->reader = function ($reader, $stream) {
                     $stream->open(STREAM_MODE_READ);
                     $bytes = '';
                     do {
                         $bytes .= $stream->read();
                     } while (!$stream->eof());
                     $stream->close();
                     return $reader->readImageFromString($bytes);
                 };
             }
         } else {
             throw new IllegalArgumentException('Expected either an io.streams.InputStream or an io.Stream, have ' . xp::typeOf($this->stream));
         }
     }
 }
 /**
  * Unmarshal XML to an object
  *
  * @param   xml.parser.InputSource source
  * @param   string classname
  * @param   [:var] inject
  * @return  lang.Object
  * @throws  lang.ClassNotFoundException
  * @throws  xml.XMLFormatException
  * @throws  lang.reflect.TargetInvocationException
  * @throws  lang.IllegalArgumentException
  */
 public function unmarshalFrom(InputSource $input, $classname, $inject = array())
 {
     libxml_clear_errors();
     $doc = new DOMDocument();
     if (!$doc->load(Streams::readableUri($input->getStream()))) {
         $e = libxml_get_last_error();
         throw new XMLFormatException(trim($e->message), $e->code, $input->getSource(), $e->line, $e->column);
     }
     $xpath = new XPath($doc);
     // Class factory based on tag name, reference to a static method which is called with
     // the class name and returns an XPClass instance.
     $class = XPClass::forName($classname);
     if ($class->hasAnnotation('xmlmapping', 'factory')) {
         if ($class->hasAnnotation('xmlmapping', 'pass')) {
             $factoryArgs = array();
             foreach ($class->getAnnotation('xmlmapping', 'pass') as $pass) {
                 $factoryArgs[] = self::contentOf($xpath->query($pass, $doc->documentElement));
             }
         } else {
             $factoryArgs = array($doc->documentElement->nodeName);
         }
         $class = $class->getMethod($class->getAnnotation('xmlmapping', 'factory'))->invoke(NULL, $factoryArgs);
     }
     return self::recurse($xpath, $doc->documentElement, $class, $inject);
 }
 /**
  * Read an image
  *
  * @return  resource
  * @throws  img.ImagingException
  */
 public function readImage()
 {
     return $this->readImage0(Streams::readableUri($this->stream));
 }
 public function is_file()
 {
     $this->assertTrue(is_file(Streams::readableUri(new MemoryInputStream('Hello'))));
 }
 public function largefileGetContents()
 {
     $data = str_repeat('x', 16384);
     $this->assertEquals($data, file_get_contents(Streams::readableUri(new MemoryInputStream($data))));
 }