InputStreamReader.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*
  3. * $Id: InputStreamReader.php 905 2010-10-05 16:28:03Z mrook $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. include_once 'phing/system/io/PhingFile.php';
  22. include_once 'phing/system/io/Reader.php';
  23. /**
  24. * Writer class for OutputStream objects.
  25. *
  26. * Unlike the Java counterpart, this class does not (yet) handle
  27. * character set transformations. This will be an important function
  28. * of this class with move to supporting PHP6.
  29. *
  30. * @package phing.system.io
  31. */
  32. class InputStreamReader extends Reader {
  33. /**
  34. * @var InputStream
  35. */
  36. protected $inStream;
  37. /**
  38. * Construct a new InputStreamReader.
  39. * @param InputStream $$inStream InputStream to read from
  40. */
  41. public function __construct(InputStream $inStream) {
  42. $this->inStream = $inStream;
  43. }
  44. /**
  45. * Close the stream.
  46. */
  47. public function close() {
  48. return $this->inStream->close();
  49. }
  50. /**
  51. * Skip over $n bytes.
  52. * @param int $n
  53. */
  54. public function skip($n) {
  55. return $this->inStream->skip($n);
  56. }
  57. /**
  58. * Read data from file.
  59. * @param int $len Num chars to read.
  60. * @return string chars read or -1 if eof.
  61. */
  62. public function read($len = null) {
  63. return $this->inStream->read($len);
  64. }
  65. /**
  66. * Marks the current position in this input stream.
  67. * @throws IOException - if the underlying stream doesn't support this method.
  68. */
  69. public function mark() {
  70. $this->inStream->mark();
  71. }
  72. /**
  73. * Whether the attached stream supports mark/reset.
  74. * @return boolean
  75. */
  76. public function markSupported() {
  77. return $this->inStream->markSupported();
  78. }
  79. /**
  80. * Repositions this stream to the position at the time the mark method was last called on this input stream.
  81. * @throws IOException - if the underlying stream doesn't support this method.
  82. */
  83. public function reset() {
  84. $this->inStream->reset();
  85. }
  86. /**
  87. * Whether eof has been reached with stream.
  88. * @return boolean
  89. */
  90. public function eof() {
  91. return $this->inStream->eof();
  92. }
  93. /**
  94. * Reads a entire file and stores the data in the variable
  95. * passed by reference.
  96. *
  97. * @param string $file String. Path and/or name of file to read.
  98. * @param object &$rBuffer Reference. Variable of where to put contents.
  99. *
  100. * @return TRUE on success. Err object on failure.
  101. * @author Charlie Killian, charlie@tizac.com
  102. * @deprecated Use read() or BufferedReader instead.
  103. */
  104. public function readInto(&$rBuffer) {
  105. return $this->inStream->readInto($rBuffer);
  106. }
  107. /**
  108. * Returns string representation of attached stream.
  109. * @return string
  110. */
  111. public function getResource() {
  112. return $this->inStream->__toString();
  113. }
  114. }