Read chunk from file at specified position. If this was the last chunk,
sets the eof property. Returns a null chunk in case of error.
343466
def read(self, bytes, offset):
        
        return Zchunk(lib.zfile_read(self._as_parameter_, bytes, offset), True)
471291
public int read() throws IOException {
    if (this.bytesRead == this.length) {
      // All chunks and final additional chunk are read.
      // This means we have reached EOF.
      return -1;
    }

    try {
      // Read a chunk from given input stream when
      // it is first chunk or all bytes in chunk body is read
      if (this.streamBytesRead == 0 || this.chunkPos == this.chunkBody.length) {
        // Check if there are data available to read from given input stream.
        if (this.streamBytesRead != this.streamSize) {
          // Send all data chunks.
          int chunkSize = CHUNK_SIZE;
          if (this.streamBytesRead + chunkSize > this.streamSize) {
            chunkSize = this.streamSize - this.streamBytesRead;
          }

          if (readChunk(chunkSize) < 0) {
            return -1;
          }

          this.streamBytesRead += chunkSize;
        } else {
          // Send final additional chunk to complete chunk upload.
          byte[] chunk = new byte[0];
          createChunkBody(chunk);
        }
      }

      this.bytesRead++;
      // Value must be between 0 to 255.
      int value = this.chunkBody[this.chunkPos] & 0xFF;
      this.chunkPos++;
      return value;
    } catch (NoSuchAlgorithmException | InvalidKeyException | InsufficientDataException | InternalException e) {
      throw new IOException(e.getCause());
    }
  }
102036
@Override
  public synchronized int read(byte buf[], int off, int len) throws IOException {
    dfsClient.checkOpen();
    if (closed) {
      dfsClient.incReadExpCntToStats();

      throw new IOException("Stream closed");
    }
    DFSClient.dfsInputStreamfailures.set(0);
    long start = System.currentTimeMillis();
    
    if (pos < getFileLength() || (pos == getFileLength() && len == 0)) {
      int retries = 2;
      while (retries > 0) {
        try {
          // If position equals or is larger than the end position of the
          // block, we try to seek to the next block, unless:
          // 1. user tries to read 0 bytes (usually by available() call), AND
          // 2. there is at least a known block for the file (blockEnd != -1), AND
          // 3. pos is the end of the file, AND
          // 4. the end of the block is the end of the file
          //    (the current block is the known last block of the file)
          // For this case, we want to stay in the current block, as in the case
          // that it is the last block (which is almost always true given
          // len == 0), the current block is the under-construction block whose size
          // you want to update.
          //
          if (len == 0) { // called by available()
            if (blockEnd == -1 // No current block selected
                || pos == getFileLength()) { // at the end of the file
              currentNode = blockSeekTo(pos, false);
              if (currentNode == null) {
                // In this case, user wants to know available information of
                // the file, but the file doesn't have any block created yet (it
                // is a 0 size file). Simply 0 should be returned.
                return 0;
              }
            } else {
              throw new IOException(
                  "Try to read 0 bytes while current position is not the end of the file");
            }
          } else if (pos > blockEnd
              || (this.isCurrentBlockUnderConstruction && blockReader != null
                  && blockReader.eos && blockReader.available() == 0)) {
            currentNode = blockSeekTo(pos, true);
          }
          
          int realLen = (int) Math.min((long) len, (blockEnd - pos + 1L));
          int result = readBuffer(buf, off, realLen);

          if (result >= 0) {
            pos += result;
          } else if (len != 0){
            // got a EOS from reader though we expect more data on it.
            throw new IOException("Unexpected EOS from the reader");
          }
          if (dfsClient.stats != null && result != -1) {
            dfsClient.stats.incrementBytesRead(result);
          }
          long timeval = System.currentTimeMillis() - start;
          dfsClient.metrics.incReadTime(timeval);
          dfsClient.metrics.incReadSize(result);
          dfsClient.metrics.incReadOps();
          return (result >= 0) ? result : 0;
        } catch (InterruptedIOException iie) {
          throw iie;
        } catch (ChecksumException ce) {
          dfsClient.incReadExpCntToStats();

          throw ce;
        } catch (IOException e) {
          dfsClient.incReadExpCntToStats();

          if (retries == 1) {
            DFSClient.LOG.warn("DFS Read: " + StringUtils.stringifyException(e));
          }
          blockEnd = -1;
          if (currentNode != null) { addToDeadNodes(currentNode); }
          if (--retries == 0) {
            if (len != 0) {
              throw e;
            } else {
              // When called by available(). No need to fail the query. In that case
              // available() value might not be updated, but it's OK.
              return 0;
            }
          }
        }
      }
    }
    return -1;
  }
870191
public int doRead(ByteChunk chunk) {
        if (!isNeedToRead()) {
            // Read only once.
            return -1;
        }

        read = true;

        final int readableBytes = content.length();
        chunk.setBytes(content.array(), content.offset(), readableBytes);

        return readableBytes;
    }
504609
def read_chunks(file, size=io.DEFAULT_BUFFER_SIZE):
    """"""
    while True:
        chunk = file.read(size)
        if not chunk:
            break
        yield chunk
849593
@Override
	public int read(byte[] b) throws IOException {

		if (b == null )
			throw new EOFException("Target byte array is null");

		return this.read(b, 0, b.length);
	}
1036001
def _read(self):
        
        filepos = self._fp.tell()
        if filepos < 1:
            return ""
        destpos = max(filepos - self._chunk_size, 0)
        self._fp.seek(destpos)
        buf = self._fp.read(filepos - destpos)
        self._fp.seek(destpos)
        return buf
954910
public @Nullable byte[] peek() throws IOException {
    if (closed) throw new IllegalStateException("closed");
    if (isEmpty()) return null;
    int length = first.length;
    byte[] data = new byte[length];
    ringRead(first.position + Element.HEADER_LENGTH, data, 0, length);
    return data;
  }
120843
async def read_chunk(self, size: int=chunk_size) -> bytes:
        
        if self._at_eof:
            return b''
        if self._length:
            chunk = await self._read_chunk_from_length(size)
        else:
            chunk = await self._read_chunk_from_stream(size)

        self._read_bytes += len(chunk)
        if self._read_bytes == self._length:
            self._at_eof = True
        if self._at_eof:
            newline = await self._content.readline()
            assert newline == self._newline, \
                'reader did not read all the data or it is malformed'
        return chunk
1353775
def readonce(self, size = None):
        
        if self.eof:
            raise EOFError
        if self.errored:
            raise IOError('Stream is broken before EOF')
        if size is not None and size < len(self.data) - self.pos:
            ret = self.data[self.pos: self.pos + size]
            self.pos += size
            return ret
        else:
            ret = self.data[self.pos:]
            self.pos = len(self.data)
            if self.dataeof:
                self.eof = True
            return ret
1207808
public int read(byte[] b, int off, int len) throws IOException {
        checkForClosed();
        if (b == null) {
            throw new NullPointerException();
        } else if ((off < 0) || (len < 0) || ((off + len) > b.length)) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return 0;
        }

        loadBytesAsNeeded();
        int bytesImmediatelyAvailable = bytesLeftInBuffer();
        if (len <= bytesImmediatelyAvailable) {
            System.arraycopy(_bytes, _currentBufferPosition, b, off, len);
            _currentBufferPosition += len;
            return len;
        }

        int bytesRead = EOF;
        if (bytesImmediatelyAvailable > 0) {
            bytesRead = read(b, off, bytesImmediatelyAvailable);
            if (bytesRead != EOF) {
                int furtherBytesRead = read(b, off + bytesRead, len - bytesRead);
                if (furtherBytesRead != EOF) {
                    bytesRead += furtherBytesRead;
                }
            }
        }
        return bytesRead;
    }
1318041
def read_line(self):
    
    while True:
      newline_idx = self.buf.find(b"\n")
      if newline_idx >= 0:
        res = self.buf[:newline_idx]
        self.buf = self.buf[newline_idx + 1:]
        return res
      chunk = self.f.recv(4096)
      if not chunk:
        raise EndOfStreamError()
      self.buf += chunk
436468
async def readchunk(self) -> Tuple[bytes, bool]:
        
        while True:
            if self._exception is not None:
                raise self._exception

            while self._http_chunk_splits:
                pos = self._http_chunk_splits.pop(0)
                if pos == self._cursor:
                    return (b"", True)
                if pos > self._cursor:
                    return (self._read_nowait(pos-self._cursor), True)
                internal_logger.warning('Skipping HTTP chunk end due to data '
                                        'consumption beyond chunk boundary')

            if self._buffer:
                return (self._read_nowait_chunk(-1), False)
                # return (self._read_nowait(-1), False)

            if self._eof:
                # Special case for signifying EOF.
                # (b'', True) is not a final return value actually.
                return (b'', False)

            await self._wait('readchunk')
642710
def read_chunks(filepath, chunk_size):
    """"""
    try:
        with open(filepath, 'rb') as f:
            while True:
                chunk = f.read(chunk_size)
                if chunk:
                    yield chunk
                else:
                    break  # EOF
    except OSError as e:
        raise error.ReadError(e.errno, filepath)
102925
def read(self, size=-1):
        """"""
        if size == 0:
            return b''
        elif size < 0:
            from_buf = self._read_from_buffer()
            self._current_pos = self._content_length
            return from_buf + self._raw_reader.read()

        #
        # Return unused data first
        #
        if len(self._buffer) >= size:
            return self._read_from_buffer(size)

        #
        # If the stream is finished, return what we have.
        #
        if self._eof:
            return self._read_from_buffer()

        #
        # Fill our buffer to the required size.
        #
        # logger.debug('filling %r byte-long buffer up to %r bytes', len(self._buffer), size)
        self._fill_buffer(size)
        return self._read_from_buffer(size)
705112
def get_starting_chunk(filename, length=1024):
    
    # Ensure we open the file in binary mode
    try:
        with open(filename, 'rb') as f:
            chunk = f.read(length)
            return chunk
    except IOError as e:
        print(e)
477034
private int read1(byte b[], int off, int len)
  throws IOException {
    int avail = count-pos;
    if( avail <= 0 ) {
      if(len>=buf.length) {
        // read a chunk to user buffer directly; avoid one copy
        int nread = readChecksumChunk(b, off, len);
        return nread;
      } else {
        // read a chunk into the local buffer
        fill();
        if( count <= 0 ) {
          return -1;
        } else {
          avail = count;
        }
      }
    }
    
    // copy content of the local buffer to the user buffer
    int cnt = (avail < len) ? avail : len;
    System.arraycopy(buf, pos, b, off, cnt);
    pos += cnt;
    return cnt;    
  }