Read the next chunk and return it.

@param resource $handle
@param int      $chunkSize

@return string|null
508509
protected function readNext($handle, $chunkSize)
    {
        if (feof($handle)) {
            return null;
        }

        return $this->filesystem->read($handle, $chunkSize);
    }
1278907
public function read($handle)
	{
		if (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
			throw new Exception('Argument must be stream resource.');
		}

		$stat = fstat($handle);

		$sql = '';
		$delimiter = ';';
		$count = $size = 0;

		while (!feof($handle)) {
			$s = fgets($handle);
			$size += strlen($s);
			if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') {
				$delimiter = trim(substr($s, 10));

			} elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) {
				$sql .= substr($ts, 0, -strlen($delimiter));
				if (!$this->connection->query($sql)) {
					throw new Exception($this->connection->error . ': ' . $sql);
				}
				$sql = '';
				$count++;
				if ($this->onProgress) {
					call_user_func($this->onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : null);
				}

			} else {
				$sql .= $s;
			}
		}

		if (rtrim($sql) !== '') {
			$count++;
			if (!$this->connection->query($sql)) {
				throw new Exception($this->connection->error . ': ' . $sql);
			}
			if ($this->onProgress) {
				call_user_func($this->onProgress, $count, isset($stat['size']) ? 100 : null);
			}
		}

		return $count;
	}
69065
def _GetChunkForReading(self, chunk):
    """"""
    try:
      return self.chunk_cache.Get(chunk)
    except KeyError:
      pass

    # We don't have this chunk already cached. The most common read
    # access pattern is contiguous reading so since we have to go to
    # the data store already, we read ahead to reduce round trips.

    missing_chunks = []
    for chunk_number in range(chunk, chunk + 10):
      if chunk_number not in self.chunk_cache:
        missing_chunks.append(chunk_number)

    self._ReadChunks(missing_chunks)
    # This should work now - otherwise we just give up.
    try:
      return self.chunk_cache.Get(chunk)
    except KeyError:
      raise aff4.ChunkNotFoundError("Cannot open chunk %s" % chunk)
717395
public function read($bytesRequested)
    {
        if($this->_currentPart >= count($this->_parts)) {
          return FALSE;
        }

        $activePart = $this->_parts[$this->_currentPart];
        $buffer = $activePart->read($bytesRequested);

        while(strlen($buffer) < $bytesRequested) {
          $this->_currentPart += 1;
          $nextBuffer = $this->read($bytesRequested - strlen($buffer));
          if($nextBuffer === FALSE) {
            break;
          }
          $buffer .= $nextBuffer;
        }

        return $buffer;
    }
1272599
final protected function next(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
        if ($this->_next) {
            return $this->_next->process($request, $handler);
        }
        return $handler->handle($request);
    }
852793
@Override
    public Chunk<byte[], BytesReference> readChunk() throws IOException {
        Chunk<byte[], BytesReference> chunk = internalReadChunk();
        if (chunk != null) {
            processChunk(chunk);
        }
        return chunk;
    }
871865
public function getChunkString()
    {
        if (!$this->curChunkSize) {
            return false;
        }
        $chunk = $this->read($this->curChunkSize);
        $this->curChunkSize = null;
        return $chunk;
    }
907869
protected function readNext($handle, $chunkSize)
    {
        if (feof($handle)) {
            return null;
        }

        $line = $this->readLine($handle, $chunkSize);

        return $line === '' ? $this->readNext($handle, $chunkSize) : $line;
    }
536911
public function nextChunk($chunk = false)
  {
    if (false == $this->resumeUri) {
      $this->resumeUri = $this->fetchResumeUri();
    }

    if (false == $chunk) {
      $chunk = substr($this->data, $this->progress, $this->chunkSize);
    }
    $lastBytePos = $this->progress + strlen($chunk) - 1;
    $headers = array(
      'content-range' => "bytes $this->progress-$lastBytePos/$this->size",
      'content-type' => $this->request->getRequestHeader('content-type'),
      'content-length' => $this->chunkSize,
      'expect' => '',
    );

    $httpRequest = new Request(
        $this->resumeUri,
        'PUT',
        $headers,
        $chunk
    );
    return $this->makePutRequest($httpRequest);
  }
419025
public function readFileHandle($file_handle)
    {
        if (!is_resource($file_handle))
            throw new \InvalidArgumentException("No file handle was provided");

        $data = array();
        $this->file_handle = $file_handle;

        foreach ($this as $row)
            $data[] = $row;

        return $data;
    }
303832
protected function readPart($handle, PartBuilder $partBuilder)
    {
        $partBuilder->setStreamPartStartPos(ftell($handle));
        
        if ($partBuilder->canHaveHeaders()) {
            $this->readHeaders($handle, $partBuilder);
            $this->lastLineSeparatorLength = 0;
        }
        if ($partBuilder->getParent() === null && !$partBuilder->isMime()) {
            $this->readUUEncodedOrPlainTextMessage($handle, $partBuilder);
        } else {
            $this->readPartContent($handle, $partBuilder);
        }
    }
484993
public function batch($chunkSize)
    {
        $this->iterator = Iterators::batch($this->iterator, $chunkSize);
        return $this;
    }
1360997
function getBlock(handle) {
			var block = {
				handle: handle,
				rows: []
			};
			blocks.push(block);
			return block;
		}
973670
protected function getCsv($handle)
    {
        return fgetcsv($handle, 0, $this->delimiter, $this->enclosure, $this->escape);
    }
658859
@Override
	public final int next(int handle) throws DataStoreException
    {
        if (SAFE_MODE) checkHandle(handle);
        
        int current = nextBlock[handle];
        while (current != -1 && (flags[current] & FLAG_START_BLOCK) == 0)
            current = nextBlock[current];

        return current;
    }
1220620
protected function fetchBatch($attempt = 1, $chunkSize = null)
    {
        if ($this->isFinished) {
            return;
        }

        $results = $this->client->getXML($this->url('', [
            'path'   => $this->resumptionToken ? null : $this->path,
            'limit'  => $chunkSize ?: $this->chunkSize,
            'token'  => $this->resumptionToken,
            'filter' => $this->filter ? str_replace(['\''], ['&apos;'], $this->filter) : null,
        ]));

        $results->registerXPathNamespaces([
            'rowset'  => 'urn:schemas-microsoft-com:xml-analysis:rowset',
            'xsd'     => 'http://www.w3.org/2001/XMLSchema',
            'saw-sql' => 'urn:saw-sql',
        ]);

        $this->readColumnHeaders($results);

        $rows = $results->all('//rowset:Row');

        foreach ($rows as $row) {
            $this->resources[] = $this->convertToResource($row);
        }

        $this->resumptionToken = $results->text('/report/QueryResult/ResumptionToken') ?: $this->resumptionToken;
        $this->isFinished = ($results->text('/report/QueryResult/IsFinished') === 'true');

        if (!count($rows) && !$this->isFinished) {
            // If the Analytics server spends too long time preparing the results, it can
            // sometimes return an empty result set. If this happens, we should just wait
            // a little and retry the request.
            // See: https://bitbucket.org/uwlib/uwlib-alma-analytic-tools/wiki/Understanding_Analytic_GET_Requests#!analytic-still-loading
            if ($attempt >= self::$maxAttempts) {
                // Give up
                throw new RequestFailed(
                    'Not getting any data from the Analytics server - max number of retries exhausted.'
                );
            }
            // Sleep for a few seconds, then retry
            sleep(self::$retryDelayTime);
            $this->fetchBatch($attempt + 1);
        }
    }
253214
private function readLine($handle)
    {
        $size = 4096;
        $ret = $line = fgets($handle, $size);
        while (strlen($line) === $size - 1 && substr($line, -1) !== "\n") {
            $line = fgets($handle, $size);
        }
        return $ret;
    }