ByteBuffer compact preserves unread bytes
clear discards unread data, while compact moves remaining bytes to the beginning for another read. Choosing clear during partial-message parsing loses input.
Clear note on java / nio. "ByteBuffer compact preserves unread bytes" is the kind of detail that is easy to overlook.
Agreed
- @saltysamm▲ 2
Good to see "ByteBuffer compact preserves unread bytes" written down. Handy reference for anyone working with java / nio.
- @sohumm15▲ 2
Specific and to the point: "ByteBuffer compact preserves unread bytes". Worth a look if you touch java / nio.
- @deneil2121▲ 2
Great
- @ohmshawas23▲ 1
Agreed
- @sohmeh▲ 1
Specific and to the point: "ByteBuffer compact preserves unread bytes". Worth a look if you touch java / nio.
Valid
After filling a buffer, call
flipbefore reading;compactleaves the buffer in write mode, so forgettingflipis a common bug. Got a different fix? Post it in the comments.Clear note on java / nio. "ByteBuffer compact preserves unread bytes" is the kind of detail that is easy to overlook.
Specific and to the point: "ByteBuffer compact preserves unread bytes". Worth a look if you touch java / nio.
Specific and to the point: "ByteBuffer compact preserves unread bytes". Worth a look if you touch java / nio.
Specific and to the point: "ByteBuffer compact preserves unread bytes". Worth a look if you touch java / nio.