Java 8 ByteBuffer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ByteBuffer class.

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: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: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: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
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:clear, flip, put, slice
        Text startKey = partitioner.getRangeEndKey(partitioner.getRangeNum() - 2);
        byteBuffer.put(startKey.getBytes(), 0, startKey.getLength());
        byteBuffer.put(newline);
      } else { 
        Text startKey = partitioner.getRangeEndKey(range_no - 1);
        byteBuffer.put(startKey.getBytes(), 0, startKey.getLength());
        byteBuffer.put(newline);
        Text endKey = partitioner.getRangeEndKey(range_no);
        byteBuffer.put(endKey.getBytes(), 0, endKey.getLength());
        byteBuffer.put(newline);
      } 
    } 
 
    private void writeCurrentByteBuffer(boolean is_last) throws IOException {
      byteBuffer.flip();
      ByteBuffer tmpByteBuf = byteBuffer.slice();
      ByteBuffer output = sstableBuilder.append(tmpByteBuf, is_first, is_last, is_include_min, is_include_max);
      if (output != null) {
        byte[] reslutBuf = new byte[output.capacity()];
        output.get(reslutBuf);

8
CodeRank
This code example shows how to use the following methods:mark, reset, put
    public ByteBuffer clone(ByteBuffer buffer)
    { 
        assert buffer != null;
        ByteBuffer cloned = allocate(buffer.remaining());
 
        cloned.mark();
        cloned.put(buffer.duplicate());
        cloned.reset();
        return cloned;
    } 
 
    public abstract ByteBuffer allocate(int size);
 
    public abstract long getMinimumSize(); 
} 
8
CodeRank

Related Java 8 ByteBuffer Questions & Answers:

See Code Examples for Java 8 ByteBuffer Methods: