Fills the buffer with more data, taking into account shuffling and other
tricks for dealing with marks. Assumes that it is being called by a method.
This method also assumes that all data has already been read in, hence pos
> count.
421153
private void _fill () throws IOException
  {
    byte [] buffer = _getBufIfOpen ();
    if (m_nMarkPos < 0)
      m_nPos = 0; /* no mark: throw away the buffer */
    else
      if (m_nPos >= buffer.length) /* no room left in buffer */
        if (m_nMarkPos > 0)
        {
          /* can throw away early part of the buffer */
          final int sz = m_nPos - m_nMarkPos;
          System.arraycopy (buffer, m_nMarkPos, buffer, 0, sz);
          m_nPos = sz;
          m_nMarkPos = 0;
        }
        else
          if (buffer.length >= m_nMarkLimit)
          {
            /* buffer got too big, invalidate mark */
            m_nMarkPos = -1;
            /* drop buffer contents */
            m_nPos = 0;
          }
          else
          {
            /* grow buffer */
            int nsz = m_nPos * 2;
            if (nsz > m_nMarkLimit)
              nsz = m_nMarkLimit;
            final byte [] nbuf = new byte [nsz];
            System.arraycopy (buffer, 0, nbuf, 0, m_nPos);
            if (!s_aBufUpdater.compareAndSet (this, buffer, nbuf))
            {
              // Can't replace buf if there was an async close.
              // Note: This would need to be changed if fill()
              // is ever made accessible to multiple threads.
              // But for now, the only way CAS can fail is via close.
              // assert buf == null;
              throw new IOException ("Stream closed");
            }
            buffer = nbuf;
          }
    m_nCount = m_nPos;
    // Potentially blocking read
    final int n = _getInIfOpen ().read (buffer, m_nPos, buffer.length - m_nPos);
    if (n > 0)
      m_nCount = n + m_nPos;
  }
466817
private void fillTotalCount(JsonObject summary) {
    if (totalCount == 0 && summary != null && summary.get("total_count") != null) {
      totalCount = summary.getLong("total_count", totalCount);
    }
  }
1316222
private boolean fillLast() throws IOException {
        int count;

        if (lastFilled == pageSize) {
            throw new IllegalStateException();
        }
        count = src.read(pages[lastNo], lastFilled, pageSize - lastFilled);
        if (count <= 0) {
            if (count == 0) {
                throw new IllegalStateException();
            }
            return false;
        }
        lastFilled += count;
        return true;
    }
1168642
public void seek(long pos) throws IOException
    {
        long inSegmentPos = pos - segmentOffset;
        if (inSegmentPos < 0 || inSegmentPos > buffer.capacity())
            throw new IOException(String.format("Seek position %d is not within mmap segment (seg offs: %d, length: %d)", pos, segmentOffset, buffer.capacity()));

        seekInternal((int) inSegmentPos);
    }
875064
private void fill() throws IOException {
        int dst;
        if (markedChar <= UNMARKED) {
            /* No mark */
            dst = 0;
        } else {
            /* Marked */
            int delta = nextChar - markedChar;
            if (delta >= readAheadLimit) {
                /* Gone past read-ahead limit: Invalidate mark */
                markedChar = INVALIDATED;
                readAheadLimit = 0;
                dst = 0;
            } else {
                if (readAheadLimit <= cb.length) {
                    /* Shuffle in the current buffer */
                    System.arraycopy(cb, markedChar, cb, 0, delta);
                    markedChar = 0;
                    dst = delta;
                } else {
                    /* Reallocate buffer to accommodate read-ahead limit */
                    //
                    // Android-changed: Use the same strategy as BufferedInputStream,
                    // i.e, double the size of the buffer on each fill. Do not directly
                    // size the buffer to the readAheadLimit.
                    //
                    // char ncb[] = new char[readAheadLimit];
                    int nlength = cb.length * 2;
                    if (nlength > readAheadLimit) {
                        nlength = readAheadLimit;
                    }
                    char ncb[] = new char[nlength];
                    System.arraycopy(cb, markedChar, ncb, 0, delta);
                    cb = ncb;
                    markedChar = 0;
                    dst = delta;
                }
                nextChar = nChars = delta;
            }
        }

        int n;
        do {
            n = in.read(cb, dst, cb.length - dst);
        } while (n == 0);
        if (n > 0) {
            nChars = dst + n;
            nextChar = dst;
        }
    }
1095885
private void _advance(int count) {
        if (buf != null) {
            bufPos += count;
            if (bufPos == buf.length) {
                buf = null;
            }
        } else {
            pos.setIndex(pos.getIndex() + count);
            if (pos.getIndex() > text.length()) {
                pos.setIndex(text.length());
            }
        }
    }
1163749
def insert_lines(self, count=None):
        
        count = count or 1
        top, bottom = self.margins or Margins(0, self.lines - 1)

        # If cursor is outside scrolling margins it -- do nothin'.
        if top <= self.cursor.y <= bottom:
            self.dirty.update(range(self.cursor.y, self.lines))
            for y in range(bottom, self.cursor.y - 1, -1):
                if y + count <= bottom and y in self.buffer:
                    self.buffer[y + count] = self.buffer[y]
                self.buffer.pop(y, None)

            self.carriage_return()
155241
private void fillBuffer() throws IOException {
        if (!endOfInput && (lastCoderResult == null || lastCoderResult.isUnderflow())) {
            encoderIn.compact();
            int position = encoderIn.position();
            // We don't use Reader#read(CharBuffer) here because it is more efficient
            // to write directly to the underlying char array (the default implementation
            // copies data to a temporary char array).
            int c = reader.read(encoderIn.array(), position, encoderIn.remaining());
            if (c == -1) {
                endOfInput = true;
            } else {
                encoderIn.position(position + c);
            }
            encoderIn.flip();
        }
        encoderOut.compact();
        lastCoderResult = encoder.encode(encoderIn, encoderOut, endOfInput);
        encoderOut.flip();
    }
657031
protected int fill (byte[] buffer, int offset, int count) throws KryoException {
		if (inputStream == null) return -1;
		try {
			return inputStream.read(buffer, offset, count);
		} catch (IOException ex) {
			throw new KryoException(ex);
		}
	}
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;
  }
1104868
private boolean performFlushIfRequired() throws IOException {
        if (anyAreSet(state, FLUSHING_BUFFER)) {
            final ByteBuffer[] bufs = new ByteBuffer[additionalBuffer == null ? 1 : 2];
            long totalLength = 0;
            bufs[0] = currentBuffer.getBuffer();
            totalLength += bufs[0].remaining();
            if (additionalBuffer != null) {
                bufs[1] = additionalBuffer;
                totalLength += bufs[1].remaining();
            }
            if (totalLength > 0) {
                long total = 0;
                long res = 0;
                do {
                    res = next.write(bufs, 0, bufs.length);
                    total += res;
                    if (res == 0) {
                        return false;
                    }
                } while (total < totalLength);
            }
            additionalBuffer = null;
            currentBuffer.getBuffer().clear();
            state = state & ~FLUSHING_BUFFER;
        }
        return true;
    }
461944
int findNextUsedLinePos(int pos) {

        try {
            int     firstPos   = pos;
            int     currentPos = pos;
            boolean wasCR      = false;

            dataFile.seek(pos);

            while (true) {
                int c = dataFile.read();

                currentPos++;

                switch (c) {

                    case CR_CHAR :
                        wasCR = true;
                        break;

                    case LF_CHAR :
                        wasCR = false;

                        ((RowInputText) rowIn).skippedLine();

                        firstPos = currentPos;
                        break;

                    case ' ' :
                        if (wasCR) {
                            wasCR = false;

                            ((RowInputText) rowIn).skippedLine();
                        }
                        break;

                    case -1 :
                        return -1;

                    default :
                        return firstPos;
                }
            }
        } catch (IOException e) {
            throw new HsqlException(e.getMessage(), "", 0);
        }
    }
1053685
protected void flush() throws IOException {
		if (this.tempStream != null && this.buffer.position() > 0) {
			final int pos = this.buffer.position();
			this.buffer.rewind();
			this.buffer.limit(pos);

			this.tempStream.write(this.buffer);

			this.buffer.rewind();
			this.buffer.limit(this.buffer.capacity());

			this.bufferPosition += pos;
		}
	}
282912
private void handleReadBuffer() throws IOException {
        if (readBuffer.remaining() == 0) {
            readBuffer.clear();
            actualFile.read(actualFileOffset, readBuffer);
            actualFileOffset += readBuffer.limit();
            readBuffer.position(0);
        }
    }
1319021
private MessageBuffer prepareNumberBuffer(int readLength)
            throws IOException
    {
        int remaining = buffer.size() - position;
        if (remaining >= readLength) {
            // When the data is contained inside the default buffer
            nextReadPosition = position;
            position += readLength;  // here assumes following buffer.getXxx never throws exception
            return buffer; // Return the default buffer
        }
        else {
            // When the default buffer doesn't contain the whole length,
            // fill the temporary buffer from the current data fragment and
            // next fragment(s).

            int off = 0;
            if (remaining > 0) {
                numberBuffer.putMessageBuffer(0, buffer, position, remaining);
                readLength -= remaining;
                off += remaining;
            }

            while (true) {
                nextBuffer();
                int nextSize = buffer.size();
                if (nextSize >= readLength) {
                    numberBuffer.putMessageBuffer(off, buffer, 0, readLength);
                    position = readLength;
                    break;
                }
                else {
                    numberBuffer.putMessageBuffer(off, buffer, 0, nextSize);
                    readLength -= nextSize;
                    off += nextSize;
                }
            }

            nextReadPosition = 0;
            return numberBuffer;
        }
    }
1310049
def _read_from_buffer(self, pos: int) -> None:
        
        self._read_bytes = self._read_delimiter = self._read_regex = None
        self._read_partial = False
        self._finish_read(pos, False)
1145319
public static void clearToFill(ByteBuffer buffer) {
        if (buffer != null) {
            buffer.position(0);
            buffer.limit(buffer.capacity());
        }
    }