本文整理汇总了PHP中FileReader::close方法的典型用法代码示例。如果您正苦于以下问题:PHP FileReader::close方法的具体用法?PHP FileReader::close怎么用?PHP FileReader::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _readFile
/**
* Reading a file.
*
* @param PhingFile $file The file to read
* @return string
* @access protected
**/
protected function _readFile(PhingFile $file)
{
$input = new FileReader($file);
$buffer = $input->read();
$input->close();
return $buffer;
}
示例2: copyFrom
/**
* @param IFile $file The source file to copy from.
* @return bool TRUE if the file has been successfully copied from $file, FALSE if an error occured
* Note: An exception is raised if an important error is detected (the copy of a single file failed),
* but during a folder copy, a failure during the copy of a single "sub-file" is ignored and no
* exception is raised.
* Nevertheless, you can check if the copy was a full success by testing the returned value.
* @throws EyeIOException
* @throws EyeFileNotFoundException
*/
protected function copyFrom(IFile $file, $overwrite = true)
{
if ($this->isDirectory() && (!$file->isDirectory() || $this->getName() != $file->getName())) {
if ($this->getName() != '/' || $file->getName() != '/') {
return $this->getChildFile($file->getName())->copyFrom($file, $overwrite);
}
}
if ($this->exists() && !$overwrite) {
throw new EyeIOException($this->path . '" exists and can\'t be overwritten.');
}
//FILE or LINK
if ($file->isFile() || $file->isLink()) {
$srcPath = AdvancedPathLib::getPhpLocalHackPath($file->getPath());
$destPath = AdvancedPathLib::getPhpLocalHackPath($this->path);
// First, let's try with the function provided by PHP, but only working with
// a very restricted range of filesystems
if (copy($srcPath, $destPath)) {
return true;
}
if (!$this->exists() && !$this->createNewFile(true)) {
throw new EyeIOException('Unable to create destination file ' . $this->path . '.');
}
try {
$fileWriter = new FileWriter($this->getOutputStream());
$fileReader = new FileReader($file->getInputStream());
$buffer = null;
while ($fileReader->read($buffer) !== 0) {
$fileWriter->write($buffer);
}
$fileReader->close();
$fileWriter->close();
return true;
} catch (Exception $e) {
if (is_object($fileReader)) {
$fileReader->close();
}
if (is_object($fileWriter)) {
$fileWriter->close();
}
throw new EyeIOException('Unable to transfer files contents ' . $file->getPath() . ' => ' . $this->path . '.', 0, $e);
}
} elseif ($file->isDirectory()) {
if ($this->isDirectory() || $this->mkdirs()) {
$success = true;
foreach ($file->listFiles() as $subFile) {
try {
if (!$subFile->copyTo($this)) {
$success = false;
}
} catch (Exception $e) {
$success = false;
}
}
return $success;
} else {
throw new EyeIOException('Unable to create destination directory ' . $this->path . '.');
}
} else {
throw new EyeFileNotFoundException($file->getPath() . ' does not exist.');
}
}