/** * @inheritdoc * @param StreamInterface $destination * @param int|null $bufferSize */ public function copyTo(StreamInterface $destination, $bufferSize = null) { if (null === $destination) { throw new Exception\InvalidArgumentException('destination'); } if (!$this->canRead() && !$this->canWrite()) { throw new Exception\ObjectDisposedException('this'); } if (!$destination->canRead() && !$destination->canWrite()) { throw new Exception\ObjectDisposedException('destination'); } if (!$this->canRead()) { throw new Exception\NotSupportedException(); } if (!$destination->canWrite()) { throw new Exception\NotSupportedException(); } $this->internalCopyTo($destination, $bufferSize); }
/** * @return bool */ public function canRead() { return $this->stream->canRead(); }
public function copyTo(StreamInterface $destination, $bufferSize = null) { if (null === $destination) { throw new Exception\InvalidArgumentException('destination'); } if (!$this->canRead() && !$this->canWrite()) { throw new Exception\ObjectDisposedException('this'); } if (!$destination->canRead() && !$destination->canWrite()) { throw new Exception\ObjectDisposedException('destination'); } if (!$this->canRead()) { throw new Exception\NotSupportedException(); } if (!$destination->canWrite()) { throw new Exception\NotSupportedException(); } if (null !== $bufferSize && $bufferSize <= 0) { throw new Exception\InvalidArgumentException('bufferSize', $bufferSize, 'Parameter "bufferSize" must be greater than 0.'); } // Copy in chunks $bufferSize = $bufferSize ?: $this->defaultCopyBufferSize; while (($data = $this->read($bufferSize)) !== null) { $destination->write($data); } }
/** * @return bool */ public function canRead() { $this->initializeStream(); return $this->stream->canRead(); }