Best code examples for Java 8 ByteBuffer class (java.nio.ByteBuffer)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ByteBuffer class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 ByteBuffer examples from Open Source projects
This code example shows how to use the following methods: position, remaining, array, arrayOffset, hasArray
98:	if (buffer.hasArray()) { 
99:	return new BytesArray(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: capacity, limit, position
83:	bb.limit(Math.min(off + len, bb.capacity())); 
84:	bb.position(off); 
-
88:	int read = channel.read(bb, position); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: position, remaining, arrayOffset, get
43:	return o2.remaining() == 0 ? 0 : -1; 
-
45:	if (o2.remaining() == 0) 
-
50:	int diff = o1.get(o1.position() + o1.arrayOffset()) - o2.get(o2.position() + o2.arrayOffset()); 
-
54:	return ByteBufferUtil.compareUnsigned(o1, o2); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: hasRemaining, remaining, get
35:	if (!buffer.hasRemaining()) { 
-
39:	len = Math.min(len, buffer.remaining()); 
40:	buffer.get(b, off, len); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: mark, position, reset, put, ByteBuffer.position
53:	bb.position(pos); 
54:	bb.mark(); 
55:	bb.put(s.getBytes()); 
56:	bb.reset(); 
57:	assert bb.position() == pos; 
-
68:	assert s.equals(ByteBufferUtil.string(bb, 10, s.length())); 
-
71:	assert s.equals(ByteBufferUtil.string(bb, 10, s.length())); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: position, remaining, get
40:	return o2.remaining() == 0 ? 0 : -1; 
-
42:	if (o2.remaining() == 0) 
-
47:	int diff = o1.get(o1.position()) - o2.get(o2.position()); 
-
52:	return ByteBufferUtil.compareUnsigned(o1, o2); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: capacity, limit, position, remaining, isDirect
50:	Assert.assertEquals(0, newBuffer.position()); 
51:	Assert.assertEquals(10, newBuffer.capacity()); 
52:	Assert.assertEquals(10, newBuffer.limit()); 
53:	Assert.assertEquals(10, newBuffer.remaining()); 
54:	Assert.assertTrue(newBuffer.isDirect()); 
-
64:	Assert.assertEquals(0, newBuffer.position()); 
65:	Assert.assertEquals(10, newBuffer.capacity()); 
66:	Assert.assertEquals(10, newBuffer.limit()); 
67:	Assert.assertEquals(10, newBuffer.remaining()); 
68:	Assert.assertTrue(newBuffer.isDirect()); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: limit, position, remaining, asReadOnlyBuffer, get
103:	size = (buffer.remaining() - numBufferBytes) / numBytes; 
-
170:	byte versionFromBuffer = buffer.get(); 
-
173:	int numBytes = buffer.get(); 
174:	int size = buffer.getInt(); 
175:	ByteBuffer bufferToUse = buffer.asReadOnlyBuffer(); 
176:	bufferToUse.limit(bufferToUse.position() + size); 
177:	buffer.position(bufferToUse.limit()); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: clear, flip, put, slice
173:	byteBuffer.put(startKey.getBytes(), 0, startKey.getLength()); 
174:	byteBuffer.put(newline); 
-
176:	byteBuffer.put(endKey.getBytes(), 0, endKey.getLength()); 
177:	byteBuffer.put(newline); 
-
182:	byteBuffer.flip(); 
183:	ByteBuffer tmpByteBuf = byteBuffer.slice(); 
-
193:	byteBuffer.clear(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: mark, reset, put
32:	cloned.mark(); 
33:	cloned.put(buffer.duplicate()); 
34:	cloned.reset(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: limit, position, duplicate, get
40:	int length = (bb.get() & 0xFF) << 8; 
41:	return length | (bb.get() & 0xFF); 
-
54:	ByteBuffer copy = bb.duplicate(); 
55:	copy.limit(copy.position() + length); 
56:	bb.position(bb.position() + length); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: limit, position, remaining, duplicate
191:	int willActuallyRead = randomInt(dst.remaining()); 
192:	ByteBuffer mockDst = dst.duplicate(); 
193:	mockDst.limit(mockDst.position() + willActuallyRead); 
-
195:	return delegate.read(mockDst); 
-
197:	dst.position(mockDst.position()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: limit, position, asReadOnlyBuffer, getInt
34:	int size = buffer.getInt(); 
35:	ByteBuffer bufferToUse = buffer.asReadOnlyBuffer(); 
36:	bufferToUse.limit(bufferToUse.position() + size); 
37:	buffer.position(bufferToUse.limit()); 
-
39:	return strategy.fromByteBuffer(bufferToUse, size); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: capacity, flip, isDirect
269:	curPacketBuf.capacity() < atLeastCapacity) { 
-
279:	curPacketBuf.flip(); 
-
289:	if (curPacketBuf != null && curPacketBuf.isDirect()) { 
290:	bufferPool.returnBuffer(curPacketBuf); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: position, get, put
19:	int current = (buffer.get(initialPos + position / 8)); 
-
22:	buffer.put(initialPos + position / 8, (byte) (current > 127 ? current - 256 : current)); 
-
29:	buffer.position(initialPos + position / 8 + ((position % 8 > 0) ? 1 : 0)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: limit, position
104:	buffer.limit(buffer.position() + numBytes); 
105:	return new IntBufferIndexedInts(buffer); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: remaining, putInt
56:	a.putInt(0xdeadbeef); 
57:	assertEquals(96, a.remaining()); 
58:	pool.returnBuffer(a); 
-
64:	assertEquals(100, a.remaining()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: isReadOnly, remaining, get, hasArray
161:	if(_payloadBuffer.isReadOnly() || ! _payloadBuffer.hasArray()) { //allocate new array 
162:	byte[] val = new byte[_payloadBuffer.remaining()]; 
163:	_payloadBuffer.get(val); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: remaining
39:	return o2.remaining() == 0 ? 0 : -1; 
-
41:	if (o2.remaining() == 0) 
-
46:	return compose(o1).compareTo(compose(o2)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: remaining, get
53:	byte[] b = new byte[buf.remaining()]; 
54:	buf.get(b); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: remaining, compareTo
35:	if ((o1 == null) || (o1.remaining() != 1)) 
-
40:	return o1.compareTo(o2); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: capacity
217:	(data.capacity() - nextFreeOffset.get()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: clear, flip
444:	bb.clear(); 
445:	ch.read(bb); 
446:	bb.flip(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: position, asLongBuffer, duplicate, putFloat
47:	ByteBuffer mutationBuffer = buf.duplicate(); 
48:	mutationBuffer.position(position); 
-
51:	mutationBuffer.asLongBuffer().put(bins); 
52:	mutationBuffer.putFloat(position + minOffset, Float.MAX_VALUE); 
53:	mutationBuffer.putFloat(position + maxOffset, Float.MIN_VALUE); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: position, remaining, array, arrayOffset, hasArray
50:	if (bb.hasArray()) { 
51:	return new Payload(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining()); 
-
54:	final byte[] b = new byte[bb.remaining()]; 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: remaining
38:	return o2.remaining() == 0 ? 0 : -1; 
-
40:	if (o2.remaining() == 0) 
-
45:	return compose(o1).compareTo(compose(o2)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: clear, flip, putLong
70:	buf.clear(); 
71:	buf.putLong(newVal); 
72:	buf.flip(); 
73:	IOUtils.writeFully(ch, buf, 0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: flip, limit, array, put, putLong
55:	input.flip(); 
56:	input.limit(MessageDecoder.MSG_ID_LENGTH); 
-
59:	input.put(addr); 
-
61:	input.putLong(offset); 
-
63:	return UtilAll.bytes2string(input.array()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: limit, position, duplicate, get
52:	final int endOfs = Math.min(buf.limit(), bufOfs + length + 1); 
-
55:	buf = buf.duplicate(); 
56:	buf.position(bufOfs); 
57:	buf.get(bytes); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: get
131:	buffer.get(short_bytes); 
-
133:	buffer.get(short_bytes); 
-
135:	buffer.get(short_bytes); 
-
137:	buffer.get(short_bytes); 
-
139:	reserved = Serialization.decodeLong(buffer); 
140:	dataOriginLength = Serialization.decodeInt(buffer); 
141:	dataCompressLength = Serialization.decodeInt(buffer); 
142:	dataChecksum = Serialization.decodeLong(buffer); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: position, rewind
180:	int oldPos = byteBuffer.position(); 
181:	byteBuffer.rewind(); 
182:	ByteString bs = ByteString.copyFrom(byteBuffer); 
183:	byteBuffer.position(oldPos); 
Full Snippet Info
8
CodeRank
Related Java 8 ByteBuffer Questions & Answers:
See Code Examples for Java 8 ByteBuffer Methods: