ByteBuffer get - top ranked examples from Open Source projects

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

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: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:position, get
        this.buffer = buffer;
    } 
 
    @Override 
    public byte get(int index) {
        return buffer.get(buffer.position() + index);
    } 
 
    @Override 
    public int length() { 
        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);
    } 
8
CodeRank
This code example shows how to use the following methods:position, get, put
    } 
 
    public void writeBits(int i, int numBits) {
        int left = 8 - position % 8;
        if (numBits <= left) {
            int current = (buffer.get(initialPos + position / 8));
            current = current < 0 ? current + 256 : current;
            current += i << (left - numBits);
            buffer.put(initialPos + position / 8, (byte) (current > 127 ? current - 256 : current));
            position += numBits;
        } else { 
            int bitsSecondWrite = numBits - left;
            writeBits(i >> bitsSecondWrite, left);
            writeBits(i & (1 << bitsSecondWrite) - 1, bitsSecondWrite);
        } 
        buffer.position(initialPos + position / 8 + ((position % 8 > 0) ? 1 : 0));
    } 
 
 
} 
8
CodeRank
This code example shows how to use the following methods:limit, position, duplicate, get
    if (length < 0)
    { 
      return ""; 
    } 
 
    final int endOfs = Math.min(buf.limit(), bufOfs + length + 1);
    final byte[] bytes = new byte[endOfs - bufOfs];
 
    buf = buf.duplicate();
    buf.position(bufOfs);
    buf.get(bytes);
    return new String(Hex.encodeHex(bytes));
  } 
 
 
  /** 
   * Strip username/password information from the JDBC DB uri to be used for logging 
   * @param uri     the JDBC URI to sanitize 
   * @return the sanitized DB URI 
   */ 
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, 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 ByteBuffer get Questions & Answers:

get Method Overview
Relative get method.
See Code Examples for other Java 8 ByteBuffer Methods: