Read chunk of data from specified offset in tempfile
343069
private void readFromTempFile(int at_offset, byte[] data, int offset, int len) throws IOException {
        if (_file_pos != at_offset) {
            _tempfile.seek((long)at_offset);
        }
        _tempfile.readFully(data,offset,len);
        _file_pos = at_offset+len;
    }
504609
def read_chunks(file, size=io.DEFAULT_BUFFER_SIZE):
    """"""
    while True:
        chunk = file.read(size)
        if not chunk:
            break
        yield chunk
138145
private boolean readNextChunkFromFile() throws IOException {
        if (readOffset >= filledUpToWhenStarted || readOffset < 0) {
            return false;
        }

        bufferedReader.clear();
        dataFile.read(readOffset, bufferedReader);
        bufferedReader.position(0);
        if (bufferedReader.limit() > 0) {
            readOffset += bufferedReader.limit();
            while (bufferedReader.remaining() > 0) {
                byte[] dst = new byte[elementSize];
                bufferedReader.get(dst);
                pendingElements.add(dst);
            }
        }
        return true;
    }
986880
public synchronized long read(long offset, final ByteBuffer buf) {
		if (!validState) {
			throw new InvalidStateException();
		}
		try {
			int readed;
			while (true) {
				if (offset >= offsetOutputCommited) {
					if (bufOutput.position() > 0) {
						log.warn("WARN: autoflush forced");
						flushBuffer();
					}
				}
				bufInput.clear();
				readed = fcInput.position(offset).read(bufInput); // Read 1 sector
				if (readed < HEADER_LEN) { // short+int (6 bytes)
					return -1;
				}
				bufInput.flip();
				final int magicB1 = (bufInput.get() & 0xFF); 	// Header - Magic (short, 2 bytes, msb-first)
				final int magicB2 = (bufInput.get() & 0xFF); 	// Header - Magic (short, 2 bytes, lsb-last)
				if (alignBlocks && (magicB1 == MAGIC_PADDING)) {
					final int diffOffset = nextBlockBoundary(offset);
					if (diffOffset > 0) {
						// log.info("WARN: skipping " + diffOffset + "bytes to next block-boundary");
						offset += diffOffset;
						continue;
					}
				}
				final int magic = ((magicB1 << 8) | magicB2);
				if (magic != MAGIC) {
					log.error("MAGIC HEADER fake=" + Integer.toHexString(magic) + " expected="
							+ Integer.toHexString(MAGIC));
					return -1;
				}
				break;
			}
			//
			final int datalen = bufInput.getInt(); 	// Header - Data Size (int, 4 bytes)
			final int dataUnderFlow = (datalen - (readed - HEADER_LEN));
			int footer = -12345678;
			if (dataUnderFlow < 0) {
				footer = bufInput.get(datalen + HEADER_LEN); 	// Footer (byte)
			}
			bufInput.limit(Math.min(readed, datalen + HEADER_LEN));
			buf.put(bufInput);
			if (dataUnderFlow > 0) {
				buf.limit(datalen);
				int len = fcInput.read(buf);
				if (len < dataUnderFlow) {
					log.error("Unable to read payload readed=" + len + " expected=" + dataUnderFlow);
					return -1;
				}
			}
			if (dataUnderFlow >= 0) {
				// Read Footer (byte)
				bufInput.clear();
				bufInput.limit(FOOTER_LEN);
				if (fcInput.read(bufInput) < FOOTER_LEN) {
					return -1;
				}
				bufInput.flip();
				footer = bufInput.get();
			}
			if (footer != MAGIC_FOOT) {
				log.error("MAGIC FOOT fake=" + Integer.toHexString(footer) + " expected="
						+ Integer.toHexString(MAGIC_FOOT));
				return -1;
			}
			buf.flip();
			return (offset + HEADER_LEN + datalen + FOOTER_LEN);
		} catch (Exception e) {
			log.error("Exception in read(" + offset + ")", e);
		}
		return -1;
	}
474977
def read(self, path, filename=None, offset=None, size=-1):
        
        storageScheme, key = self.getkey(path, filename=filename)

        if offset or (size > -1):
            if not offset:
                offset = 0
            if size > -1:
                sizeStr = offset + size - 1  # range header is inclusive
            else:
                sizeStr = ""
            headers = {"Range": "bytes=%d-%s" % (offset, sizeStr)}
            return key.get_contents_as_string(headers=headers)
        else:
            return key.get_contents_as_string()
709401
private static String getDumpBytes(WsByteBuffer buffer, int bytesToDump, boolean rewind)
   {
      // Save the current position
      int pos = buffer.position();
      if (rewind)
      {
         buffer.rewind();
      }

      byte[] data = null;
      int start;
      int count = bytesToDump;
      if (count > buffer.remaining() || count == ENTIRE_BUFFER) count = buffer.remaining();

      if (buffer.hasArray())
      {
         data = buffer.array();
         start = buffer.arrayOffset() + buffer.position();
      }
      else
      {
         data = new byte[count];
         buffer.get(data);
         start = 0;
      }

      String strData = "Dumping "+count+" bytes of buffer data:\r\n";
      if (count > 0) strData += SibTr.formatBytes(data, start, count);

      // Return the position to where it should be
      if (rewind) buffer.position(pos);

      return strData;
   }
387339
def read(self, n=1):
        
        self.offset += n
        return self.data[self.offset - n:self.offset]
1365255
public int readString(char[] buffer, int offset, int length)
        throws IOException
    {
        int readLength = 0;

        if (_chunkLength == END_OF_DATA) {
            _chunkLength = 0;
            return -1;
        }
        else if (_chunkLength == 0) {
            int tag = read();

            switch (tag) {
                case 'N':
                    return -1;

                case 'S':
                case 's':
                case 'X':
                case 'x':
                    _isLastChunk = tag == 'S' || tag == 'X';
                    _chunkLength = (read() << 8) + read();
                    break;

                default:
                    throw new IOException("expected 'S' at " + (char) tag);
            }
        }

        while (length > 0) {
            if (_chunkLength > 0) {
                buffer[offset++] = (char) parseUTF8Char();
                _chunkLength--;
                length--;
                readLength++;
            }
            else if (_isLastChunk) {
                if (readLength == 0)
                    return -1;
                else {
                    _chunkLength = END_OF_DATA;
                    return readLength;
                }
            }
            else {
                int tag = read();

                switch (tag) {
                    case 'S':
                    case 's':
                    case 'X':
                    case 'x':
                        _isLastChunk = tag == 'S' || tag == 'X';
                        _chunkLength = (read() << 8) + read();
                        break;

                    default:
                        throw new IOException("expected 'S' at " + (char) tag);
                }
            }
        }

        if (readLength == 0)
            return -1;
        else if (_chunkLength > 0 || !_isLastChunk)
            return readLength;
        else {
            _chunkLength = END_OF_DATA;
            return readLength;
        }
    }
464245
private void readChunk()
	throws IOException {

	String line = readLine(_in).trim();
	int length  = Integer.parseInt(line, 16);

	if (length > 0) {

	    // make sure the chunk will fit into the buffer

	    if (length > _buf.length) {
		_buf = new byte[length];
	    }

	    int bytesLeft = length;
	    int reqBytes = 0;
	    int off = 0;
	    int read = 0;

	    /*  multiple reads might be necessary to load
		the entire chunk */
	    while (bytesLeft != 0) {
		reqBytes = bytesLeft;
		read = _in.read(_buf, off, reqBytes);
		if (read == -1) break;
		bytesLeft -= read;
		off += read;
	    }

	    _max = off;
	    _index = 0;

	} else {
	    // end of data indicated
	    _eof = true;
	}

	_in.read(); // skip CR
	_in.read(); // skip LF

    }
350005
def _get_temp(self, content):
        """"""
        temp = None
        for line in content.splitlines():

            # make sure there's both start and end line
            if not temp:
                match = TEMP_NEEDLE.match(line)
                if match:
                    temp = match.group(1).strip()
                    continue
            else:
                match = TEMP_END_NEEDLE.match(line)
                if match:
                    return temp

        raise IndexError(self.path)
754844
def readchunk(self):
        
        received = len(self.__buffer)
        chunk_data = EMPTY
        chunk_size = int(self.chunk_size)

        if received > 0:
            chunk_data = self.__buffer
        elif self.__position < int(self.length):
            chunk_number = int((received + self.__position) / chunk_size)
            if self.__chunk_iter is None:
                self.__chunk_iter = _GridOutChunkIterator(
                    self, self.__chunks, self._session, chunk_number)

            chunk = self.__chunk_iter.next()
            chunk_data = chunk["data"][self.__position % chunk_size:]

            if not chunk_data:
                raise CorruptGridFile("truncated chunk")

        self.__position += len(chunk_data)
        self.__buffer = EMPTY
        return chunk_data
943710
def from_offset(tu, file, offset):
        
        return conf.lib.clang_getLocationForOffset(tu, file, offset)
1347862
def read(self, data, offset=0):
        
        if isinstance(data, Buffer):
            return data.read(self)

        try:
            args = list(self._struct.unpack_from(data, offset))
        except TypeError as error:
            # Working around struct.unpack_from issue #10212
            logger.debug("error: %s", error)
            args = list(self._struct.unpack_from(str(bytearray(data)), offset))
        args.reverse()
        return self.popValue(args)
112817
def Read(self, length):
    """"""
    result = b""

    # The total available size in the file
    length = int(length)
    length = min(length, self.size - self.offset)

    while length > 0:
      data = self._ReadPartial(length)
      if not data:
        break

      length -= len(data)
      result += data
    return result
944246
def _py_read1(fileObj, maxBuffer):
    '''
        
    '''
    i = 0
    ret = []
    while i < maxBuffer:
        c = fileObj.read(1)
        if c == '':
            # Stream has been closed
            break
        i += 1
        ret.append(c)
        # Use a very low timeout so we only grab more data if it's immediately available.
        (readyToRead, junk1, junk2) = select.select([fileObj], [], [], .00001)
        if not readyToRead:
            break

    return ''.join(ret)
1304294
public int read(long fileOffset, byte []buffer, int offset, int length)
    throws IOException
  {
    log.info("random-read(0x" + Long.toHexString(fileOffset) + "," + 
             length + ")");
    
    return _file.read(fileOffset, buffer, offset, length);
  }
637027
def buffered_read(fh, lock, offsets, bytecounts, buffersize=None):
    """"""
    if buffersize is None:
        buffersize = 2**26
    length = len(offsets)
    i = 0
    while i < length:
        data = []
        with lock:
            size = 0
            while size < buffersize and i < length:
                fh.seek(offsets[i])
                bytecount = bytecounts[i]
                data.append(fh.read(bytecount))
                # buffer = bytearray(bytecount)
                # n = fh.readinto(buffer)
                # data.append(buffer[:n])
                size += bytecount
                i += 1
        for segment in data:
            yield segment