Buffer remaining - 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 remaining method.

This code example shows how to use the following methods:position, remaining, array, arrayOffset, hasArray
        return tmp;
    } 
 
    @Override 
    public BytesArray toBytesArray() { 
        if (buffer.hasArray()) {
            return new BytesArray(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
        } 
        return new BytesArray(toBytes()); 
    } 
 
    @Override 
    public BytesArray copyBytesArray() { 
        return new BytesArray(toBytes()); 
    } 
 
    @Override 
    public ChannelBuffer toChannelBuffer() { 
        return ChannelBuffers.wrappedBuffer(buffer);
    } 
10
CodeRank
This code example shows how to use the following methods:position, remaining, arrayOffset, get
 
    public static int compareLongs(ByteBuffer o1, ByteBuffer o2)
    { 
        if (o1.remaining() == 0)
        { 
            return o2.remaining() == 0 ? 0 : -1;
        } 
        if (o2.remaining() == 0)
        { 
            return 1; 
        } 
 
        int diff = o1.get(o1.position() + o1.arrayOffset()) - o2.get(o2.position() + o2.arrayOffset());
        if (diff != 0)
            return diff;
 
        return ByteBufferUtil.compareUnsigned(o1, o2);
    } 
 
    public ByteBuffer fromString(String source) throws MarshalException

9
CodeRank
This code example shows how to use the following methods:hasRemaining, remaining, get
        return buffer.get();
    } 
 
    @Override 
    public int read(byte[] b, int off, int len) throws IOException {
        if (!buffer.hasRemaining()) {
            return -1; 
        } 
 
        len = Math.min(len, buffer.remaining());
        buffer.get(b, off, len);
        return len;
    } 
 
    @Override 
    public long skip(long n) throws IOException {
        if (n > buffer.remaining()) {
            int ret = buffer.position();
            buffer.position(buffer.limit());
            return ret;
9
CodeRank
This code example shows how to use the following methods:position, remaining, get
 
    public int compare(ByteBuffer o1, ByteBuffer o2)
    { 
        if (o1.remaining() == 0)
        { 
            return o2.remaining() == 0 ? 0 : -1;
        } 
        if (o2.remaining() == 0)
        { 
            return 1; 
        } 
 
        int diff = o1.get(o1.position()) - o2.get(o2.position());
        if (diff != 0)
            return diff;
 
 
        return ByteBufferUtil.compareUnsigned(o1, o2);
    } 
 

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:remaining, putInt
  } 
   
  @Test 
  public void testBuffersAreReset() { 
    ByteBuffer a = pool.getBuffer(100);
    a.putInt(0xdeadbeef);
    assertEquals(96, a.remaining());
    pool.returnBuffer(a);
 
    // Even though we return the same buffer, 
    // its position should be reset to 0 
    ByteBuffer b = pool.getBuffer(100);
    assertSame(a, b);
    assertEquals(100, a.remaining());
    pool.returnBuffer(b);
  } 
   
  @Test 
  public void testWeakRefClearing() { 
    // Allocate and return 10 buffers. 
8
CodeRank
This code example shows how to use the following methods:isReadOnly, remaining, get, hasArray
  public byte[] getValueBytes() 
  { 
    if(_payloadBuffer == null)
      return null; 
 
    if(_payloadBuffer.isReadOnly() || ! _payloadBuffer.hasArray()) { //allocate new array
      byte[] val = new byte[_payloadBuffer.remaining()];
      _payloadBuffer.get(val);
      return val;
    } 
    // else 
    return _payloadBuffer.array();
 
  } 
  public int getValueLength() { 
    if(_payloadBuffer == null)
      return 0; 
 
    return _payloadBuffer.remaining();
  } 
8
CodeRank
This code example shows how to use the following methods:remaining
 
    public int compare(ByteBuffer o1, ByteBuffer o2)
    { 
        if (o1.remaining() == 0)
        { 
            return o2.remaining() == 0 ? 0 : -1;
        } 
        if (o2.remaining() == 0)
        { 
            return 1; 
        } 
 
        return compose(o1).compareTo(compose(o2));
    } 
 
    public ByteBuffer fromString(String source) throws MarshalException
    { 
      // Return an empty ByteBuffer for an empty string. 
      if (source.isEmpty())
          return ByteBufferUtil.EMPTY_BYTE_BUFFER; 
8
CodeRank
This code example shows how to use the following methods:remaining, get
    dos.flush();
    return baos.toByteArray();
  } 
   
  private static byte[] remainingAsArray(ByteBuffer buf) {
    byte[] b = new byte[buf.remaining()];
    buf.get(b);
    return b;
  } 
   
  @Test 
  public void testReceiveAndMirror() throws IOException { 
    PacketReceiver pr = new PacketReceiver(false);
 
    // Test three different lengths, to force reallocing 
    // the buffer as it grows. 
    doTestReceiveAndMirror(pr, 100, 10);
    doTestReceiveAndMirror(pr, 50, 10);
    doTestReceiveAndMirror(pr, 150, 10);
 
8
CodeRank

Related Buffer remaining Questions & Answers:

remaining Method Overview
Returns the number of elements between the current position and the limit.
See Code Examples for other Java 8 Buffer Methods: