summaryrefslogtreecommitdiff
path: root/buildscripts/phing/classes/phing/system/io/BufferedReader.php
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/phing/classes/phing/system/io/BufferedReader.php')
-rwxr-xr-x[-rw-r--r--]buildscripts/phing/classes/phing/system/io/BufferedReader.php62
1 files changed, 30 insertions, 32 deletions
diff --git a/buildscripts/phing/classes/phing/system/io/BufferedReader.php b/buildscripts/phing/classes/phing/system/io/BufferedReader.php
index 4946985c..a392f5be 100644..100755
--- a/buildscripts/phing/classes/phing/system/io/BufferedReader.php
+++ b/buildscripts/phing/classes/phing/system/io/BufferedReader.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: BufferedReader.php,v 1.6 2005/12/27 19:12:13 hlellelid Exp $
+ * $Id: 98ea5952d7a41ce47ce95008e336f38758946aaa $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -21,15 +21,15 @@
include_once 'phing/system/io/Reader.php';
-/*
+/**
* Convenience class for reading files.
*
* @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
- * @version $Revision: 1.6 $ $Date: 2005/12/27 19:12:13 $
+ * @version $Id$
* @access public
* @see FilterReader
* @package phing.system.io
-*/
+ */
class BufferedReader extends Reader {
private $bufferSize = 0;
@@ -53,37 +53,36 @@ class BufferedReader extends Reader {
}
/**
- * Reads and returns $_bufferSize chunk of data.
+ * Reads and returns a chunk of data.
+ * @param int $len Number of bytes to read. Default is to read configured buffer size number of bytes.
* @return mixed buffer or -1 if EOF.
*/
function read($len = null) {
- // ignore $len param, not sure how to hanlde it, since
- // this should only read bufferSize amount of data.
- if ($len !== null) {
- $this->currentPosition = ftell($this->fd);
- }
- if ( ($data = $this->in->read($this->bufferSize)) !== -1 ) {
-
- // not all files end with a newline character, so we also need to check EOF
- if (!$this->in->eof()) {
-
- $notValidPart = strrchr($data, "\n");
- $notValidPartSize = strlen($notValidPart);
-
- if ( $notValidPartSize > 1 ) {
- // Block doesn't finish on a EOL
- // Find the last EOL and forgot all following stuff
- $dataSize = strlen($data);
- $validSize = $dataSize - $notValidPartSize + 1;
-
- $data = substr($data, 0, $validSize);
-
- // Rewind to the begining of the forgotten stuff.
- $this->in->skip(-$notValidPartSize+1);
- }
-
- } // if !EOF
+ // if $len is specified, we'll use that; otherwise, use the configured buffer size.
+ if ($len === null) $len = $this->bufferSize;
+
+ if ( ($data = $this->in->read($len)) !== -1 ) {
+
+ // not all files end with a newline character, so we also need to check EOF
+ if (!$this->in->eof()) {
+
+ $notValidPart = strrchr($data, "\n");
+ $notValidPartSize = strlen($notValidPart);
+
+ if ( $notValidPartSize > 1 ) {
+ // Block doesn't finish on a EOL
+ // Find the last EOL and forget all following stuff
+ $dataSize = strlen($data);
+ $validSize = $dataSize - $notValidPartSize + 1;
+
+ $data = substr($data, 0, $validSize);
+
+ // Rewind to the begining of the forgotten stuff.
+ $this->in->skip(-$notValidPartSize+1);
+ }
+
+ } // if !EOF
}
return $data;
}
@@ -167,4 +166,3 @@ class BufferedReader extends Reader {
return $this->in->getResource();
}
}
-?>