本文整理汇总了PHP中BufferedReader::read方法的典型用法代码示例。如果您正苦于以下问题:PHP BufferedReader::read方法的具体用法?PHP BufferedReader::read怎么用?PHP BufferedReader::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferedReader
的用法示例。
在下文中一共展示了BufferedReader::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* Returns the next character in the filtered stream. If the desired
* number of lines have already been read, the resulting stream is
* effectively at an end. Otherwise, the next character from the
* underlying stream is read and returned.
*
* @param int $len
* @return int|string the next character in the resulting stream, or -1
* if the end of the resulting stream has been reached
*
* @throws IOException if the underlying stream throws an IOException
* during reading
* @throws BuildException
*/
public function read($len = 0)
{
// do the "singleton" initialization
if (!$this->getInitialized()) {
$this->initialize();
$this->setInitialized(true);
}
$ch = -1;
// The readers return -1 if they end. So simply read the "prepend"
// after that the "content" and at the end the "append" file.
if ($this->prependReader !== null) {
$ch = $this->prependReader->read();
if ($ch === -1) {
// I am the only one so I have to close the reader
$this->prependReader->close();
$this->prependReader = null;
}
}
if ($ch === -1) {
$ch = parent::read();
}
if ($ch === -1 && $this->appendReader !== null) {
$ch = $this->appendReader->read();
if ($ch === -1) {
// I am the only one so I have to close the reader
$this->appendReader->close();
$this->appendReader = null;
}
}
return $ch;
}
示例2: setFile
/**
* set the text using a file
* @param file the file to use
* @throws BuildException if the file does not exist, or cannot be
* read
*/
public function setFile(PhingFile $file)
{
// non-existing files are not allowed
if (!$file->exists()) {
throw new BuildException("File " . $file . " does not exist.");
}
$reader = null;
try {
if ($this->encoding == null) {
$reader = new BufferedReader(new FileReader($file));
} else {
$reader = new BufferedReader(new InputStreamReader(new FileInputStream($file)));
}
$this->value = $reader->read();
} catch (IOException $ex) {
$reader->close();
throw new BuildException($ex);
}
$reader->close();
}