StringInputStream.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Ivan Y. Khvostishkov                            *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: StringInputStream.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class StringInputStream extends InputStream
00017     {
00018         private $string     = null;
00019         private $length     = null;
00020         
00021         private $position   = 0;
00022         private $mark       = 0;
00023         
00024         public function __construct($string)
00025         {
00026             Assert::isString($string);
00027             
00028             $this->string = $string;
00029             $this->length = strlen($string);
00030         }
00031         
00035         public static function create($string)
00036         {
00037             return new self($string);
00038         }
00039         
00040         public function isEof()
00041         {
00042             return ($this->position >= $this->length);
00043         }
00044         
00048         public function mark()
00049         {
00050             $this->mark = $this->position;
00051             
00052             return $this;
00053         }
00054         
00055         public function markSupported()
00056         {
00057             return true;
00058         }
00059         
00063         public function reset()
00064         {
00065             $this->position = $this->mark;
00066             
00067             return $this;
00068         }
00069         
00073         public function close()
00074         {
00075             $this->string = null;
00076             
00077             return $this;
00078         }
00079         
00080         public function read($count)
00081         {
00082             if (!$this->string || $this->isEof())
00083                 return null;
00084             
00085             $result = substr($this->string, $this->position, $count);
00086             
00087             $this->position += $count;
00088             
00089             return $result;
00090         }
00091     }
00092 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4