Completed
Push — master ( 2e5bdd...9e2471 )
by Ryuichi
05:26
created

InputStreamReader   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
cbo 1
dl 0
loc 83
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0
lcom 1
1
<?php
2
namespace WebStream\IO\Reader;
3
4
use WebStream\IO\InputStream;
5
6
/**
7
 * InputStreamReader
8
 * @author Ryuichi TANAKA.
9
 * @since 2016/02/05
10
 * @version 0.7
11
 */
12
class InputStreamReader
13
{
14
    /**
15
     * @var InputStream 入力ストリーム
16
     */
17
    protected $stream;
18
19
    /**
20
     * constructor
21
     * @param InputStream $stream 入力ストリーム
22
     */
23
    public function __construct(InputStream $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
     */
39
    public function close()
40
    {
41
        $this->stream->close();
42
    }
43
44
    /**
45
     * 入力ストリームからデータを読み込む
46
     * @return string 読み込みデータ
47
     */
48
    public function read()
49
    {
50
        $args = func_get_args();
51
        $length = count($args) === 1 ? $args[0] : null;
52
53
        return $this->stream->read($length);
54
    }
55
56
    /**
57
     * 入力ストリームから行単位でデータを読み込む
58
     * 末尾に改行コードは含まない
59
     * @return string 読み込みデータ
60
     */
61
    public function readLine()
62
    {
63
        return $this->stream->readLine();
64
    }
65
66
    /**
67
     * 入力ストリームから指定バイト数後方へポインタを移動する
68
     * @param int $pos 後方への移動バイト数(負数の場合は前方へ移動)
69
     * @return int $skipNum 移動したバイト数、移動に失敗した場合-1
70
     */
71
    public function skip(int $pos)
72
    {
73
        return $this->stream->skip($pos);
74
    }
75
76
    /**
77
     * 最後にmarkされた位置に再配置する
78
     * @throws IOException
79
     */
80
    public function reset()
81
    {
82
        $this->stream->reset();
83
    }
84
85
    /**
86
     * 入力ストリームの現在位置にmarkを設定する
87
     * @param int マークするバイト位置
88
     * @throws IOException
89
     */
90
    public function mark()
91
    {
92
        $this->stream->mark();
93
    }
94
}
95