/** * Put data from one buffer into another, avoiding over/under flows * @param from Buffer to take bytes from in flush mode * @param to Buffer to put bytes to in flush mode. The buffer is flipToFill before the put and flipToFlush after. * @return number of bytes moved * @deprecated use {@link #append(ByteBuffer, ByteBuffer)} */ public static int flipPutFlip(ByteBuffer from, ByteBuffer to) { return append(to,from); }
/** * Put data from one buffer into another, avoiding over/under flows * @param from Buffer to take bytes from in flush mode * @param to Buffer to put bytes to in flush mode. The buffer is flipToFill before the put and flipToFlush after. * @return number of bytes moved * @deprecated use {@link #append(ByteBuffer, ByteBuffer)} */ public static int flipPutFlip(ByteBuffer from, ByteBuffer to) { return append(to,from); }
private void put(ByteBuffer source) { BufferUtil.append(buffer, source); }
/** * Put data from one buffer into another, avoiding over/under flows * @param from Buffer to take bytes from in flush mode * @param to Buffer to put bytes to in flush mode. The buffer is flipToFill before the put and flipToFlush after. * @return number of bytes moved * @deprecated use {@link #append(ByteBuffer, ByteBuffer)} */ public static int flipPutFlip(ByteBuffer from, ByteBuffer to) { return append(to,from); }
private void put(ByteBuffer source) { BufferUtil.append(buffer, source); }
private ByteBuffer preserve(final ByteBuffer dst, final int newLimit, final int oldLimit) { ByteBuffer buf = BufferUtil.allocate(newLimit - oldLimit); ByteBuffer slice = dst.slice(); slice.position(oldLimit); slice.limit(newLimit); BufferUtil.append(buf, slice); return buf; } }
@Override public void onContent(Response response, ByteBuffer content) { int length = content.remaining(); if (length > BufferUtil.space(buffer)) { int requiredCapacity = buffer == null ? length : buffer.capacity() + length; if (requiredCapacity > maxLength) response.abort(new IllegalArgumentException("Buffering capacity " + maxLength + " exceeded")); int newCapacity = Math.min(Integer.highestOneBit(requiredCapacity) << 1, maxLength); buffer = BufferUtil.ensureCapacity(buffer, newCapacity); } BufferUtil.append(buffer, content); }
@Override public int fill(ByteBuffer buffer) throws IOException { if (_closed) throw new EofException("CLOSED"); if (_in==null) shutdownInput(); if (_ishut) return -1; int filled=BufferUtil.append(buffer,_in); if (filled>0) notIdle(); return filled; }
filled=BufferUtil.append(buffer,in); if (BufferUtil.isEmpty(in)) _inQ.poll();
@Override public void write(int b) throws IOException { if (isClosed()) throw new EOFException("Closed"); if (_aggregate == null) _aggregate = _channel.getByteBufferPool().acquire(getBufferSize(), OUTPUT_BUFFER_DIRECT); BufferUtil.append(_aggregate, (byte)b); _written++; // Check if all written or full if (!closeIfAllContentWritten() && BufferUtil.isFull(_aggregate)) _channel.write(_aggregate, false); }
@Override public void write(int b) throws IOException { if (isClosed()) throw new EOFException("Closed"); if (_aggregate == null) _aggregate = _channel.getByteBufferPool().acquire(getBufferSize(), OUTPUT_BUFFER_DIRECT); BufferUtil.append(_aggregate, (byte)b); _written++; // Check if all written or full if (!closeIfAllContentWritten() && BufferUtil.isFull(_aggregate)) _channel.write(_aggregate, false); }
filled=BufferUtil.append(buffer,in); if (BufferUtil.isEmpty(in)) _inQ.poll();
filled=BufferUtil.append(buffer,in); if (BufferUtil.isEmpty(in)) _inQ.poll();
if (size<=_inflated.capacity()) BufferUtil.append(_inflated,chunk); release(chunk);
if (size<=_inflated.capacity()) BufferUtil.append(_inflated,chunk); release(chunk);
private Action batch() { if (aggregate == null) { aggregate = bufferPool.acquire(bufferSize, true); if (LOG.isDebugEnabled()) LOG.debug("{} acquired aggregate buffer {}", this, aggregate); } for (FrameEntry entry : entries) { entry.generateHeaderBytes(aggregate); ByteBuffer payload = entry.frame.getPayload(); if (BufferUtil.hasContent(payload)) BufferUtil.append(aggregate, payload); } if (LOG.isDebugEnabled()) LOG.debug("{} aggregated {} frames: {}", this, entries.size(), entries); // We just aggregated the entries, so we need to succeed their callbacks. succeeded(); return Action.SCHEDULED; }