Get an OutputBuffer containing a subset of the current one

@param limit How many bytes should be available
@return a new OutputContext
544168
public OutputContext getSlice(int limit) {
        List<ByteBuffer> newBufs = new LinkedList<ByteBuffer>();
        ByteBuffer buf = ByteBuffer.allocate(limit);
        Iterator<ByteBuffer> iter = buffers.iterator();

        while (iter.hasNext() && buf.position() < buf.limit()) {
            ByteBuffer cur = iter.next();
            int diff = buf.limit() - buf.position();
            if (diff > cur.limit()) {
                buf.put(cur);
                iter.remove();
            } else {
                ByteBuffer slice = cur.duplicate();
                slice.limit(diff);
                buf.put(slice);
            }
        }
        return new OutputContext(newBufs);
    }
470841
@Override
    public ByteBuffer getBuffer()
    {
        //  If we are expected to read large message, we'll opt for zero-
        //  copy, i.e. we'll ask caller to fill the data directly to the
        //  message. Note that subsequent read(s) are non-blocking, thus
        //  each single read reads at most SO_RCVBUF bytes at once not
        //  depending on how large is the chunk returned from here.
        //  As a consequence, large messages being received won't block
        //  other engines running in the same I/O thread for excessive
        //  amounts of time.
        if (toRead >= bufsize) {
            zeroCopy = true;
            return readPos.duplicate();
        }
        else {
            zeroCopy = false;
            buf.clear();
            return buf;
        }
    }
693470
public SpatialViewQuery limit(final int limit) {
        if (limit < 0) {
            throw new IllegalArgumentException("Limit must be >= 0.");
        }
        params[PARAM_LIMIT_OFFSET] = "limit";
        params[PARAM_LIMIT_OFFSET+1] = Integer.toString(limit);
        return this;
    }
1045374
@Override
    public java.util.concurrent.Future<ListTablesResult> listTablesAsync(Integer limit) {

        return listTablesAsync(new ListTablesRequest().withLimit(limit));
    }
526581
public ByteBuffer frameAndReturnBuffer ()
    {
        // flip the buffer which will limit it to its current position
        _buffer.flip();

        // then write the frame length and rewind back to the start of the
        // buffer so that all the data is available
        int count = _buffer.limit();
        _buffer.put((byte)((count >>> 24) & 0xFF));
        _buffer.put((byte)((count >>> 16) & 0xFF));
        _buffer.put((byte)((count >>>  8) & 0xFF));
        _buffer.put((byte)((count >>>  0) & 0xFF));
        _buffer.rewind();

        return _buffer;
    }
278097
protected ByteBuffer allocateBuffer() {
		if (_buffersToReuse != null && !_buffersToReuse.isEmpty()) {
			ByteBuffer bb = _buffersToReuse.poll();
			bb.rewind();
			bb.limit(bb.capacity());
			return bb;
		}
		ByteBuffer r = StaticBuffers.getInstance().byteBuffer(BUFFER_KEY, _bufferSize);
		r.limit(_bufferSize);
		return r.order(_order);
	}
444311
public MessageBuffer toMessageBuffer()
    {
        if (list.size() == 1) {
            return list.get(0);
        }
        else if (list.isEmpty()) {
            return MessageBuffer.allocate(0);
        }
        else {
            return MessageBuffer.wrap(toByteArray());
        }
    }
648240
public static String genLimitSQL(Integer offset, Integer limit) {
		StringBuilder sb = new StringBuilder();
		if (limit != null) {
			sb.append(" limit ");
			if(offset != null) {
				sb.append(offset).append(",");
			}
			sb.append(limit);
		}
		return sb.toString();
	}
1264683
public ObjectManagerByteArrayOutputStream[] getBuffers()
                    throws ObjectManagerException
    {
        final String methodName = "getBuffers";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName);

        ObjectManagerByteArrayOutputStream[] buffers = new ObjectManagerByteArrayOutputStream[2];

        // Create the buffer to contain the header for this log record.
        buffers[0] = new ObjectManagerByteArrayOutputStream((int) (4 + Token.maximumSerializedSize() + 8));

        buffers[0].writeInt(LogRecord.TYPE_CHECKPOINT_START);
        objectManagerStateToken.writeSerializedBytes(buffers[0]);
        buffers[0].writeLong(serializedBytes.getCount());

        // Now add buffers for the ObjectManagerState. 
        buffers[1] = objectManagerStateToken.getManagedObject().getSerializedBytes();

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       methodName,
                       new Object[] { buffers });
        return buffers;
    }
663215
private WsByteBuffer getBuffer() {
        WsByteBuffer buffer = this._output[this.outputIndex];
        if (null == buffer) {
            buffer = getNewByteBuffer();
            buffer.clear();
            this._output[this.outputIndex] = buffer;
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "getBuffer, new buffer -->" + buffer + " ,outputIndex -->" + this.outputIndex);
            }
        } else if (!buffer.hasRemaining()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "getBuffer, buffer  -->" + buffer + " ,outputIndex -->" + this.outputIndex + " ,outputLength -->" + this._output.length);
            }
            buffer.flip();
            this.outputIndex++;
            // next array spot may or may not exist from previous iterations
            if (null == this._output[this.outputIndex]) {
                this._output[this.outputIndex] = getNewByteBuffer();
            }
            buffer = this._output[this.outputIndex];
            buffer.clear();
        }
        return buffer;
    }
1317469
protected ByteBuf allocateBuffer(
        ChannelHandlerContext ctx,
        @SuppressWarnings("unused") AddressedEnvelope<DnsResponse, InetSocketAddress> msg) throws Exception {
        return ctx.alloc().ioBuffer(1024);
    }
696183
public synchronized byte[] getBuffer() {
        byte[] dest = new byte[buf.length];
        System.arraycopy(buf, 0, dest, 0, dest.length);
        return dest;
    }
184154
public static Output<ByteBuffer>
            from(byte[] data, boolean endOfRecord) {
        return new Output<>(ManagedBuffer.wrap(ByteBuffer.wrap(data)),
            false, endOfRecord);
    }
438520
public synchronized void mark(int limit)
        throws IllegalArgumentException
    {
        if (limit>_buf.length)
        {
            byte[] new_buf=new byte[limit];
            System.arraycopy(_buf,_pos,new_buf,_pos,_avail-_pos);
            _buf=new_buf;
            if (_byteBuffer!=null)
                _byteBuffer.setBuffer(_buf);
        }
        _mark=_pos;
    }
534499
public final static int put(IoBuffer out, IoBuffer in, int numBytesMax) {
        if (log.isTraceEnabled()) {
            log.trace("Put\nin buffer: {}\nout buffer: {}\nmax bytes: {}", new Object[] { out, in, numBytesMax });
        }
        int numBytesRead = 0;
        if (in != null) {
            int limit = Math.min(in.limit(), numBytesMax);
            byte[] inBuf = new byte[limit];
            log.trace("Bulk get size: {}", limit);
            in.get(inBuf);
            byte[] outBuf = consumeBytes(inBuf, numBytesMax);
            out.put(outBuf);
            numBytesRead = outBuf.length;
            log.trace("In pos: {}", in.position());
        }
        log.trace("Bytes put: {}", numBytesRead);
        return numBytesRead;
    }
922213
public ByteBuffer[] getBuffers(int start, int len)
    {
        if (len == 0)
        {
            return ar0;
        }
        if (len > capacity)
        {
            throw new IllegalArgumentException("len="+len+" > capacity="+capacity);
        }
        int s = start % capacity;
        int e = (start+len) % capacity;
        return getBuffersForSpan(s, e);
    }
1058909
private byte[] resizeBuffer(final Context context) {
        if (context.buffer == null) {
            context.buffer = new byte[getDefaultBufferSize()];
            context.pos = 0;
            context.readPos = 0;
        } else {
            final byte[] b = new byte[context.buffer.length * DEFAULT_BUFFER_RESIZE_FACTOR];
            System.arraycopy(context.buffer, 0, b, 0, context.buffer.length);
            context.buffer = b;
        }
        return context.buffer;
    }