Replaces the current exhausted buffer with the next buffer in the chain.
767286
private void popContentSource() {
        buffer = nextContentSource.buffer;
        position = nextContentSource.position;
        limit = nextContentSource.limit;
        nextContentSource = nextContentSource.next;
    }
506605
async def skiplast(source, n):
    
    queue = collections.deque(maxlen=n if n > 0 else 0)
    async with streamcontext(source) as streamer:
        async for item in streamer:
            if n <= 0:
                yield item
                continue
            if len(queue) == n:
                yield queue[0]
            queue.append(item)
68519
def apply_to_last(stream, fn):
    '''  '''
    assert iterable(stream), 'apply_to_last needs stream to be iterable'
    assert callable(fn), 'apply_to_last needs fn to be callable'

    stream = iter(stream)
    previous = next(stream)
    for current in stream:
        yield previous
        previous = current
    yield fn(previous)
1302237
protected void put(ByteBuffer bb) {
       if(_buffer.remaining() < bb.remaining()) {
           int newCapacity = Math.max(_buffer.capacity() << 1, _buffer.position() + bb.remaining());
           ByteBuffer b = ByteBuffer.allocate(newCapacity);
           _buffer.flip();
           b.put(_buffer);
           _buffer = b;
       }
       
       _buffer.put(bb);
    }
2614
void drainBuffers() {
        // A mostly strict ordering is achieved by observing that each buffer
        // contains tasks in a weakly sorted order starting from the last drain.
        // The buffers can be merged into a sorted array in O(n) time by using
        // counting sort and chaining on a collision.

        // Moves the tasks into the output array, applies them, and updates the
        // marker for the starting order of the next drain.
        int maxTaskIndex = moveTasksFromBuffers(tasks);
        updateDrainedOrder(tasks, maxTaskIndex);
        runTasks(tasks, maxTaskIndex);
    }
599923
function(rawBuffer) {
    if (rawBuffer && this.offset === 0) return this.buffer;

    var out = new Buffer(8);
    this.buffer.copy(out, 0, this.offset, this.offset + 8);
    return out;
  }
792533
public final void expurge() {
		Reference<? extends E> obj;

		final Iterator<R> iter = this.theSet.iterator();
		R reference;
		while (iter.hasNext()) {
			reference = iter.next();
			if (reference != null
					&& ((reference.isEnqueued()) || (reference.get() == null))) {
				reference.enqueue();
				reference.clear();
			}
		}
		while ((obj = this.queue.poll()) != null) {
			obj.clear();
			if (this.referenceType.isInstance(obj)) {
				this.theSet.remove(this.referenceType.cast(obj));
			}
		}
	}
1031041
private AbstractIoBufferEx autoExpand(int pos, int expectedRemaining) {
        if (isAutoExpand()) {
            expand(pos, expectedRemaining, true, autoExpander);
        }
        return this;
    }
681802
private void updateFrameBuffer() {

		LOG.trace("Next frame");

		if (t1 == -1 || t2 == -1) {
			t1 = System.currentTimeMillis();
			t2 = System.currentTimeMillis();
		}

		int result = new NextFrameTask(this).nextFrame();

		t1 = t2;
		t2 = System.currentTimeMillis();

		fps = (4 * fps + 1000 / (t2 - t1 + 1)) / 5;

		if (result == -1) {
			LOG.error("Timeout when requesting image!");
		} else if (result < -1) {
			LOG.error("Error requesting new frame!");
		}
	}
948057
@Override
	public void recycle(MemorySegment segment) {
		int numAddedBuffers;

		synchronized (bufferQueue) {
			// Similar to notifyBufferAvailable(), make sure that we never add a buffer
			// after releaseAllResources() released all buffers (see below for details).
			if (isReleased.get()) {
				try {
					inputGate.returnExclusiveSegments(Collections.singletonList(segment));
					return;
				} catch (Throwable t) {
					ExceptionUtils.rethrow(t);
				}
			}
			numAddedBuffers = bufferQueue.addExclusiveBuffer(new NetworkBuffer(segment, this), numRequiredBuffers);
		}

		if (numAddedBuffers > 0 && unannouncedCredit.getAndAdd(numAddedBuffers) == 0) {
			notifyCreditAvailable();
		}
	}
1168035
public static final void clearRemaining(ByteBuffer bb)
    {
        if (bb.hasArray())
        {
            Arrays.fill(bb.array(), bb.arrayOffset()+bb.position(), bb.arrayOffset()+bb.limit(), (byte)0);
        }
        else
        {
            int limit = bb.limit();
            for (int ii=bb.position();ii<limit;ii++)
            {
                bb.put(ii, (byte)0);
            }
        }
    }
37684
private void fill() throws IOException {
    int n;
    previousBufferSize += nChars;
    do {
      n = in.read(cb, 0, cb.length);
    } while (n == 0);
    if (n > 0) {
      nChars = n;
      nextChar = 0;
    }
  }
232334
public synchronized void nextFrame() {
        currentFrame++;
        if(currentFrame >= frames.size()) {
            currentFrame = 0;
        }
        super.setLines(frames.get(currentFrame));
        invalidate();
    }
1025065
private ByteBuffer successor(@Nullable ByteBuffer buf) {
        if (buf == null) {
            return ByteBuffer.allocate(0);
        }
        ByteBuffer next = ByteBuffer.allocate(buf.remaining() + 1);
        next.put(buf.duplicate());
        next.put((byte) 0);
        next.flip();
        return next;
    }
681933
private void updateCurrentAndNextSectionOfBuffer(int i) {
		int next = iterators.length + i;
		timestamps[i] = timestamps[next];
		values[i] = values[next];
		if (iterators[i].hasNext()) {
			putDataPoint(next, (Entry<Long, Double>) iterators[i].next());
		} else {
			markEndTimeSeries(i);
		}
	}
760451
private void tryFinishCurrentBufferBuilder(int targetChannel) {
		if (!bufferBuilders[targetChannel].isPresent()) {
			return;
		}
		BufferBuilder bufferBuilder = bufferBuilders[targetChannel].get();
		bufferBuilders[targetChannel] = Optional.empty();
		numBytesOut.inc(bufferBuilder.finish());
		numBuffersOut.inc();
	}
913419
public void cleanup() {
        state = null;
        if (headerBuffer != null) {
            bufferPool.deallocate(headerBuffer);
        }
        if (dataBuffer != null) {
            bufferPool.deallocate(dataBuffer);
        }
    }