Buffer limit - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Buffer limit method.

This code example shows how to use the following methods:capacity, limit, position
        if (len == 0) {
            return -1; 
        } 
 
        ByteBuffer bb = ((this.bs == bs) ? this.bb : ByteBuffer.wrap(bs));
        bb.limit(Math.min(off + len, bb.capacity()));
        bb.position(off);
 
        this.bb = bb;
        this.bs = bs;
        int read = channel.read(bb, position);
        if (read > 0) {
            position += read;
        } 
        return read;
    } 
 
    @Override 
    public boolean markSupported() { 
        return true; 
9
CodeRank
This code example shows how to use the following methods:limit, position, remaining
        return len;
    } 
 
    @Override 
    public long skip(long n) throws IOException {
        if (n > buffer.remaining()) {
            int ret = buffer.position();
            buffer.position(buffer.limit());
            return ret;
        } 
        buffer.position((int) (buffer.position() + n));
        return n;
    } 
 
    @Override 
    public void readBytes(byte[] b, int offset, int len) throws IOException {
        if (buffer.remaining() > len) {
            throw new EOFException();
        } 
        buffer.get(b, offset, len);
9
CodeRank
This code example shows how to use the following methods:limit, position, duplicate
        return buffer.remaining();
    } 
 
    @Override 
    public BytesReference slice(int from, int length) {
        ByteBuffer dup = buffer.duplicate();
        dup.position(buffer.position() + from);
        dup.limit(buffer.position() + from + length);
        return new ByteBufferBytesReference(dup);
    } 
 
    @Override 
    public StreamInput streamInput() { 
        return new ByteBufferStreamInput(buffer);
    } 
 
    @Override 
    public void writeTo(OutputStream os) throws IOException {
        if (buffer.hasArray()) {
            os.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
9
CodeRank
This code example shows how to use the following methods:capacity, limit, position, remaining, isDirect
9
CodeRank
This code example shows how to use the following methods:limit, position, remaining, asReadOnlyBuffer, get
    this.numBytes = numBytes;
 
    bitsToShift = 32 - (numBytes << 3); // numBytes * 8
 
    int numBufferBytes = 4 - numBytes;
    size = (buffer.remaining() - numBufferBytes) / numBytes;
  } 
 
  @Override 
  public int size() 
  { 
    return size;
  } 
 
  @Override 
  public int get(int index)
  { 
    return buffer.getInt(buffer.position() + (index * numBytes)) >>> bitsToShift;
  } 
 

9
CodeRank
This code example shows how to use the following methods:limit, position, duplicate, get
public abstract class AbstractCompositeType extends AbstractType<ByteBuffer>
{ 
    // changes bb position 
    public static int getShortLength(ByteBuffer bb)
    { 
        int length = (bb.get() & 0xFF) << 8;
        return length | (bb.get() & 0xFF);
    } 
 
    // changes bb position 
    public static void putShortLength(ByteBuffer bb, int length)
    { 
        bb.put((byte) ((length >> 8) & 0xFF));
        bb.put((byte) (length & 0xFF));
    } 
 
    // changes bb position 
    public static ByteBuffer getBytes(ByteBuffer bb, int length)
    { 
        ByteBuffer copy = bb.duplicate();

8
CodeRank
This code example shows how to use the following methods:limit, position, asReadOnlyBuffer, getInt
 */ 
public class ByteBufferSerializer<T> 
{ 
  public static <T> T read(ByteBuffer buffer, ObjectStrategy<T> strategy)
  { 
    int size = buffer.getInt();
    ByteBuffer bufferToUse = buffer.asReadOnlyBuffer();
    bufferToUse.limit(bufferToUse.position() + size);
    buffer.position(bufferToUse.limit());
 
    return strategy.fromByteBuffer(bufferToUse, size);
  } 
 
  public static <T> void writeToChannel(T obj, ObjectStrategy<T> strategy, WritableByteChannel channel)
      throws IOException 
  { 
    byte[] toWrite = strategy.toBytes(obj);
    channel.write(ByteBuffer.allocate(Ints.BYTES).putInt(0, toWrite.length));
    channel.write(ByteBuffer.wrap(toWrite));
  } 
9
CodeRank
This code example shows how to use the following methods:limit, position
    } 
 
    @Override 
    public IntBufferIndexedInts fromByteBuffer(ByteBuffer buffer, int numBytes)
    { 
      buffer.limit(buffer.position() + numBytes);
      return new IntBufferIndexedInts(buffer);
    } 
 
    @Override 
    public byte[] toBytes(IntBufferIndexedInts val)
    { 
      ByteBuffer buffer = val.getBuffer();
      byte[] bytes = new byte[buffer.remaining()];
      buffer.get(bytes);
 
      return bytes;
    } 
 
    @Override 
8
CodeRank
This code example shows how to use the following methods:limit, remaining, rewind
    if (off < 0 || len < 0 || off > b.length - len) {
      throw new ArrayIndexOutOfBoundsException();
    } 
     
    // Check if there is uncompressed data. 
    int n = uncompressedDirectBuf.remaining();
    if (n > 0) {
      n = Math.min(n, len);
      ((ByteBuffer)uncompressedDirectBuf).get(b, off, n);
      return n;
    } 
     
    // Re-initialize bzip2's output direct buffer. 
    uncompressedDirectBuf.rewind();
    uncompressedDirectBuf.limit(directBufferSize);
 
    // Decompress the data. 
    n = finished ? 0 : inflateBytesDirect();
    uncompressedDirectBuf.limit(n);
 

8
CodeRank
This code example shows how to use the following methods:flip, limit, array, put, putLong
    public final static int MessagePhysicOffsetPostion = 28;
    public final static int MessageStoreTimestampPostion = 56;
 
 
    public static String createMessageId(final ByteBuffer input, final ByteBuffer addr, final long offset) {
        input.flip();
        input.limit(MessageDecoder.MSG_ID_LENGTH);
 
        // 消息存储主机地址 IP PORT 8 
        input.put(addr);
        // 消息对应的物理分区 OFFSET 8 
        input.putLong(offset);
 
        return UtilAll.bytes2string(input.array());
    } 
 
 
    public static MessageId decodeMessageId(final String msgId) throws UnknownHostException {
        SocketAddress address;
        long offset;
8
CodeRank

Related Buffer limit Questions & Answers:

limit Method Overview
Returns this buffer's limit.
See Code Examples for other Java 8 Buffer Methods: