|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the LGPL. For more information please see |
|
17
|
|
|
* <http://phing.info>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Input stream subclass for file streams. |
|
22
|
|
|
* |
|
23
|
|
|
* @package phing.system.io |
|
24
|
|
|
*/ |
|
25
|
|
|
class FileInputStream extends InputStream |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The associated file. |
|
30
|
|
|
* |
|
31
|
|
|
* @var PhingFile |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $file; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Construct a new FileInputStream. |
|
37
|
|
|
* |
|
38
|
|
|
* @param PhingFile|string $file Path to the file |
|
39
|
|
|
* @throws Exception - if invalid argument specified. |
|
40
|
|
|
* @throws IOException - if unable to open file. |
|
41
|
|
|
*/ |
|
42
|
824 |
|
public function __construct($file) |
|
43
|
|
|
{ |
|
44
|
824 |
|
if ($file instanceof PhingFile) { |
|
45
|
824 |
|
$this->file = $file; |
|
46
|
5 |
|
} elseif (is_string($file)) { |
|
|
|
|
|
|
47
|
5 |
|
$this->file = new PhingFile($file); |
|
48
|
|
|
} else { |
|
49
|
|
|
throw new Exception("Invalid argument type for \$file."); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
824 |
|
if (!$this->file->exists()) { |
|
53
|
|
|
throw new IOException("Unable to open " . $this->file->__toString() . " for reading. File does not exists."); |
|
54
|
|
|
} |
|
55
|
824 |
|
if (!$this->file->canRead()) { |
|
56
|
|
|
throw new IOException("Unable to open " . $this->file->__toString() . " for reading. File not readable."); |
|
57
|
|
|
} |
|
58
|
824 |
|
$stream = @fopen($this->file->getAbsolutePath(), "rb"); |
|
59
|
824 |
|
if ($stream === false) { |
|
60
|
|
|
throw new IOException("Unable to open " . $this->file->__toString() . " for reading: " . print_r( |
|
61
|
|
|
error_get_last(), |
|
62
|
|
|
true |
|
63
|
|
|
)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
824 |
|
parent::__construct($stream); |
|
67
|
824 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns a string representation of the attached file. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
823 |
|
public function __toString() |
|
75
|
|
|
{ |
|
76
|
823 |
|
return $this->file->getPath(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Mark is supported by FileInputStream. |
|
81
|
|
|
* |
|
82
|
|
|
* @return boolean TRUE |
|
83
|
|
|
*/ |
|
84
|
|
|
public function markSupported() |
|
85
|
|
|
{ |
|
86
|
|
|
return true; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|