| 1 | <?php |
||
| 13 | class OutputStreamWriter |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var OutputStream 出力ストリーム |
||
| 17 | */ |
||
| 18 | protected $stream; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * constructor |
||
| 22 | * @param OutputStream $stream 出力ストリーム |
||
| 23 | */ |
||
| 24 | public function __construct(OutputStream $stream) |
||
| 25 | { |
||
| 26 | $this->stream = $stream; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * destructor |
||
| 31 | */ |
||
| 32 | public function __destruct() |
||
| 33 | { |
||
| 34 | $this->close(); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * バッファリングしているすべての出力バイトを書き出し、出力ストリームを閉じる |
||
| 39 | * @throws WebStream\Exception\Extend\IOException |
||
| 40 | */ |
||
| 41 | public function close() |
||
| 42 | { |
||
| 43 | $this->stream->close(); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * 出力ストリームに書き出す |
||
| 48 | * @param mixed $buf 出力データ |
||
| 49 | * @throws WebStream\Exception\Extend\IOException |
||
| 50 | */ |
||
| 51 | public function write($buf) |
||
| 52 | { |
||
| 53 | $args = func_get_args(); |
||
| 54 | $off = array_key_exists(1, $args) ? $args[1] : null; |
||
| 55 | $len = array_key_exists(2, $args) ? $args[2] : null; |
||
| 56 | |||
| 57 | $this->stream->write($buf, $off, $len); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * バッファリングしているすべての出力バイトを出力ストリームを閉じずに強制的に書き出す |
||
| 62 | * writeを実行した時点では書き出されておらず、flushした時点ですべて書き出す |
||
| 63 | * @throws WebStream\Exception\Extend\IOException |
||
| 64 | */ |
||
| 65 | public function flush() |
||
| 66 | { |
||
| 67 | $this->stream->flush(); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * 改行を書き出す |
||
| 72 | * @throws WebStream\Exception\Extend\IOException |
||
| 73 | */ |
||
| 74 | public function newLine() |
||
| 75 | { |
||
| 76 | $this->stream->write(PHP_EOL); |
||
| 77 | } |
||
| 78 | } |
||
| 79 |