Completed
Push — feature/0.7.0 ( d06a69...2e2153 )
by Ryuichi
04:48
created

OutputStreamWriter::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
namespace WebStream\IO\Writer;
3
4
use WebStream\IO\OutputStream;
5
6
/**
7
 * OutputStreamWriter
8
 * @author Ryuichi TANAKA.
9
 * @since 2016/02/24
10
 * @version 0.7
11
 */
12
class OutputStreamWriter
13
{
14
    /**
15
     * @var OutputStream 出力ストリーム
16
     */
17
    protected $stream;
18
19
    /**
20
     * constructor
21
     * @param OutputStream $stream 出力ストリーム
22
     */
23
    public function __construct(OutputStream $stream)
24
    {
25
        $this->stream = $stream;
26
    }
27
28
    /**
29
     * destructor
30
     */
31
    public function __destruct()
32
    {
33
        $this->close();
34
    }
35
36
    /**
37
     * バッファリングしているすべての出力バイトを書き出し、出力ストリームを閉じる
38
     * @throws WebStream\Exception\Extend\IOException
39
     */
40
    public function close()
41
    {
42
        $this->stream->close();
43
    }
44
45
    /**
46
     * 出力ストリームに書き出す
47
     * @param mixed $buf 出力データ
48
     * @param int $off データ開始位置
49
     * @param int $len 書き出すバイト数
50
     * @throws WebStream\Exception\Extend\IOException
51
     */
52
    public function write($buf, int $off = null, int $len = null)
53
    {
54
        $this->stream->write($buf, $off, $len);
55
    }
56
57
    /**
58
     * 改行を書き出す
59
     * @throws WebStream\Exception\Extend\IOException
60
     */
61
    public function newLine()
62
    {
63
        $this->stream->write(PHP_EOL);
64
    }
65
66
    /**
67
     * バッファリングしているすべての出力バイトを出力ストリームを閉じずに強制的に書き出す
68
     * writeを実行した時点では書き出されておらず、flushした時点ですべて書き出す
69
     * @throws WebStream\Exception\Extend\IOException
70
     */
71
    public function flush()
72
    {
73
        $this->stream->flush();
74
    }
75
}
76