Reads the next BUF_SIZE bytes into the internal buffer.
183495
private int fillBuffer() throws IOException {
    int n = super.read(buffer, 0, BUF_SIZE);
    if (n >= 0) {
      real_pos += n;
      buf_end = n;
      buf_pos = 0;
    }
    return n;
  }
1177192
private int read(ByteBuffer buf)
    {
        int nbytes;
        try {
            nbytes = fd.read(buf);
            if (nbytes == -1) {
                errno.set(ZError.ENOTCONN);
            }
            else if (nbytes == 0) {
                if (!fd.isBlocking()) {
                    //  If not a single byte can be read from the socket in non-blocking mode
                    //  we'll get an error (this may happen during the speculative read).

                    //  Several errors are OK. When speculative read is being done we may not
                    //  be able to read a single byte from the socket. Also, SIGSTOP issued
                    //  by a debugging tool can result in EINTR error.
                    errno.set(ZError.EAGAIN);
                    nbytes = -1;
                }
            }
        }
        catch (IOException e) {
            errno.set(ZError.ENOTCONN);
            nbytes = -1;
        }

        return nbytes;
    }
693999
def readBuffer(self, newLength):
        
        result = Buffer(self.buf, self.offset, newLength)
        self.skip(newLength)
        return result
513858
def read_more(size)
      return if @parser.finished?

      value = @socket.readpartial(size, @buffer)
      if value == :eof
        @parser << ""
        :eof
      elsif value
        @parser << value
      end
    rescue IOError, SocketError, SystemCallError => ex
      raise ConnectionError, "error reading from socket: #{ex}", ex.backtrace
    end
197254
public int read(byte []buf, int offset, int length) throws IOException
  {
    try {
      return readInt(buf, offset, length);
    } catch (IOException e) {
      _isKeepalive = false;
      throw e;
    } catch (RuntimeException e) {
      _isKeepalive = false;
      throw e;
    }
  }
456236
public ByteBuffer readToByteBuffer(int max) throws IOException {
        Validate.isTrue(max >= 0, "maxSize must be 0 (unlimited) or larger");
        final boolean localCapped = max > 0; // still possibly capped in total stream
        final int bufferSize = localCapped && max < DefaultSize ? max : DefaultSize;
        final byte[] readBuffer = new byte[bufferSize];
        final ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);

        int read;
        int remaining = max;

        while (true) {
            read = read(readBuffer);
            if (read == -1) break;
            if (localCapped) { // this local byteBuffer cap may be smaller than the overall maxSize (like when reading first bytes)
                if (read >= remaining) {
                    outStream.write(readBuffer, 0, remaining);
                    break;
                }
                remaining -= read;
            }
            outStream.write(readBuffer, 0, read);
        }
        return ByteBuffer.wrap(outStream.toByteArray());
    }
691145
public int read(Pointer buf, JechtIO.Str str, int max_size, int skip) {
        int len = 0;
        max_size -= skip;
        if(max_size <= 0) {
            max_size = 0;
        } else {
            IRubyObject src = port;
            IRubyObject n = RubyNumeric.int2fix(port.getRuntime(), max_size);
            IRubyObject str2 = src.callMethod(port.getRuntime().getCurrentContext(), "read", n);
            if(!str2.isNil()) {
                ByteList res = str2.convertToString().getByteList();
                len = res.realSize;
                System.arraycopy(res.bytes, res.begin, buf.buffer, buf.start+skip, len);
            }
        }
        len += skip;
        buf.buffer[buf.start+len] = 0;
        return len;
    }
911642
public static long fromByteBuffer(ByteBuffer buf) {
      if (buf.remaining() < 1) {
         // XXX make all callers check for -1
         return -1;
      }
      long first = 0x00000000000000FFL & ((long) buf.get());
      long value;
      if (first < 253) {
         // Regard this byte as a 8 bit value.
         value = 0x00000000000000FFL & ((long) first);
      } else if (first == 253) {
         // Regard the following two bytes as a 16 bit value
         if (buf.remaining() < 2) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = 0x0000000000FFFFL & ((long) buf.getShort());
      } else if (first == 254) {
         // Regard the following four bytes as a 32 bit value
         if (buf.remaining() < 4) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = 0x00000000FFFFFFFF & ((long) buf.getInt());
      } else {
         // Regard the following four bytes as a 64 bit value
         if (buf.remaining() < 8) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = buf.getLong();
      }
      return value;
   }
743266
public int readFrom(ByteBuffer src, long destOffset) {
        if (src.remaining() + destOffset >= size())
            throw new BufferOverflowException();
        int readLen = src.remaining();
        ByteBuffer b = toDirectByteBuffer(destOffset, readLen);
        b.position(0);
        b.put(src);
        return readLen;
    }
709875
public synchronized void returnBuf(byte[] buf) {
        if (buf == null || buf.length > mSizeLimit) {
            return;
        }
        mBuffersByLastUse.add(buf);
        int pos = Collections.binarySearch(mBuffersBySize, buf, BUF_COMPARATOR);
        if (pos < 0) {
            pos = -pos - 1;
        }
        mBuffersBySize.add(pos, buf);
        mCurrentSize += buf.length;
        trim();
    }
360812
def read(self, size=-1):
        """"""
        buf = self._fd.read(size)
        self._progress_cb(len(buf))
        return buf
637231
def read(self, n):
        
        buf = self._read_buf
        pos = self._read_pos
        end = pos + n

        if end <= len(buf):
            # Fast path: the data to read is fully buffered.
            self._read_pos += n
            return self._update_pos(buf[pos:end])

        # Slow path: read from the stream until enough bytes are read,
        # or until an EOF occurs or until read() would block.
        wanted = max(self.buffer_size, n)
        while len(buf) < end:
            chunk = self.raw.read(wanted)
            if not chunk:
                break
            buf += chunk

        self._read_buf = buf[end:]  # Save the extra data in the buffer.
        self._read_pos = 0
        return self._update_pos(buf[pos:end])
415554
def read(self, size=sys.maxsize):
        
        blob_size = int(self.blob_properties.get('content-length'))
        if self._pointer < blob_size:
            chunk = self._download_chunk_with_retries(
                chunk_offset=self._pointer, chunk_size=size)
            self._pointer += size
            return chunk
189858
@Override
  public int read(byte b[], int off, int len) throws IOException {
    int leftover = buf_end - buf_pos;
    if (len <= leftover) {
      System.arraycopy(buffer, buf_pos, b, off, len);
      buf_pos += len;
      return len;
    }
    for (int i = 0; i < len; i++) {
      int c = this.read();
      if (c != -1) {
        b[off + i] = (byte) c;
      } else {
        return i;
      }
    }
    return len;
  }
1067078
def read_into_buffer(buffer, size)
      tmp = read_all(size)
      i = 0
      tmp.each_byte do |byte|
        Bytes.set_string_byte(buffer, i, byte)
        i += 1
      end
      i
    end
201662
static private int readBytes(int c[], int len, InputStream is)
                throws IOException {

        byte buf[] = new byte[len];
        if (is.read(buf, 0, len) < len) {
            return -1;
        }

        // fill the passed in int array
        for (int i = 0; i < len; i++) {
             c[i] = buf[i] & 0xff;
        }
        return 0;
    }
758025
private void resizeBuf(int size)
    {
        int capacity;
        if (size >= _capacity * 2)
        {
            capacity = size;
        }
        else
        {
            capacity = 1;
            while (capacity < size)
            {
                capacity <<= 1;
            }
        }
        byte[] buf = new byte[capacity];
        if (_size > 0)
        {
            System.arraycopy(_buf, 0, buf, 0, _size);
        }
        _buf = buf;
        _capacity = capacity;
    }