Exemplo n.º 1
0
 /**
  * Reads the given amount of characters from the input stream.
  *
  * @param int    $length  The number of characters to read.
  * @param string $default The default to return if interaction is disabled.
  *
  * @return string The characters read from the input stream.
  *
  * @throws IOException If reading fails or if the input stream is closed.
  */
 public function read($length, $default = null)
 {
     if (!$this->interactive) {
         return $default;
     }
     return $this->stream->read($length);
 }
 /**
  * Reads stream contents
  *
  * @param   io.streams.InputStream is
  * @return  string bytes
  */
 protected function readAll(InputStream $is)
 {
     for ($contents = ''; $is->available();) {
         $contents .= $is->read();
     }
     $is->close();
     return $contents;
 }
Exemplo n.º 3
0
 /**
  * Read a line
  *
  * @param   io.streams.InputStream in
  * @return  string
  * @throws  lang.FormatException if no line can be read
  */
 protected function readLine(InputStream $in)
 {
     $line = '';
     while ("\n" !== ($chr = $in->read(1))) {
         $line .= $chr;
         if (!$in->available()) {
             break;
         }
     }
     return $line;
 }
 /**
  * Constructor
  *
  * @param   io.streams.InputStream in
  */
 public function __construct(InputStream $in)
 {
     // Read GZIP format header
     // * ID1, ID2 (Identification, \x1F, \x8B)
     // * CM       (Compression Method, 8 = deflate)
     // * FLG      (Flags)
     // * MTIME    (Modification time, Un*x timestamp)
     // * XFL      (Extra flags)
     // * OS       (Operating system)
     $header = unpack('a2id/Cmethod/Cflags/Vtime/Cextra/Cos', $in->read(10));
     if ("‹" != $header['id']) {
         throw new IOException('Invalid format, expected \\037\\213, have ' . addcslashes($header['id'], "..ÿ"));
     }
     if (8 != $header['method']) {
         throw new IOException('Unknown compression method #' . $header['method']);
     }
     // Now, convert stream to file handle and append inflating filter
     $wri = 'zlib.bounded://' . $in->hashCode();
     self::$wrapped[$wri] = $in;
     $this->in = fopen($wri, 'r');
     if (!stream_filter_append($this->in, 'zlib.inflate', STREAM_FILTER_READ)) {
         throw new IOException('Could not append stream filter');
     }
 }
Exemplo n.º 5
0
 /**
  * Read data from file.
  * @param int $len Num chars to read.
  * @return string chars read or -1 if eof.
  */
 public function read($len = null)
 {
     return $this->inStream->read($len);
 }
Exemplo n.º 6
0
 /**
  * Read an IOElements' contents completely into a buffer in a single call.
  *
  * @param   io.streams.InputStream s
  * @return  string
  * @throws  io.IOException
  */
 public static function readAll(InputStream $s)
 {
     $r = '';
     while ($s->available() > 0) {
         $r .= $s->read();
     }
     return $r;
 }