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);
    } 
Full Snippet Info
10
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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; 
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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;
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 ByteBuffer Questions & Answers:

See Code Examples for Java 8 ByteBuffer Methods: