Hoa central
Read.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Stringbuffer;
38 
39 use Hoa\Stream;
40 
49 class Read extends Stringbuffer implements Stream\IStream\In
50 {
56  public function eof()
57  {
58  return feof($this->getStream());
59  }
60 
68  public function read($length)
69  {
70  if (0 > $length) {
71  throw new Exception(
72  'Length must be greater than 0, given %d.',
73  0,
74  $length
75  );
76  }
77 
78  return fread($this->getStream(), $length);
79  }
80 
87  public function readString($length)
88  {
89  return $this->read($length);
90  }
91 
97  public function readCharacter()
98  {
99  return fgetc($this->getStream());
100  }
101 
107  public function readBoolean()
108  {
109  return (bool) $this->read(1);
110  }
111 
118  public function readInteger($length = 1)
119  {
120  return (int) $this->read($length);
121  }
122 
129  public function readFloat($length = 1)
130  {
131  return (float) $this->read($length);
132  }
133 
141  public function readArray($format = null)
142  {
143  return $this->scanf($format);
144  }
145 
151  public function readLine()
152  {
153  return fgets($this->getStream());
154  }
155 
162  public function readAll($offset = 0)
163  {
164  return stream_get_contents($this->getStream(), -1, $offset);
165  }
166 
173  public function scanf($format)
174  {
175  return fscanf($this->getStream(), $format);
176  }
177 
183  public function __toString()
184  {
185  return $this->readAll();
186  }
187 }
readAll($offset=0)
Definition: Read.php:162
scanf($format)
Definition: Read.php:173
readFloat($length=1)
Definition: Read.php:129
read($length)
Definition: Read.php:68
readString($length)
Definition: Read.php:87
readArray($format=null)
Definition: Read.php:141
readInteger($length=1)
Definition: Read.php:118