Buffer position - 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 position 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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:mark, position, reset, put, ByteBuffer.position
ByteBuffer tmp = ByteBuffer.allocate(l + pos + 3);
            tmp.position(3);
            bb = tmp.slice(); // make bb have a non null arrayOffset
        } 
        bb.position(pos);
        bb.mark();
        bb.put(s.getBytes());
        bb.reset();
        assert bb.position() == pos;
        return bb;
    } 
 
    @Test 
    public void testString() throws Exception 
    { 
        assert s.equals(ByteBufferUtil.string(ByteBufferUtil.bytes(s)));
 
        int pos = 10;
        ByteBuffer bb = fromStringWithPosition(s, 10, false);

9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:capacity, limit, position, remaining, isDirect
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java

Related Buffer position Questions & Answers:

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