You can flip the buffer and then create a new array with the remaining buffer size and fill it.
oldBuffer.flip();
byte[] remaining = new byte[oldBuffer.remaining()];
oldBuffer.get(remaining);
Another way in one liner with flip()and Arrays.copyOf
oldBuffer.flip();
Arrays.copyOf(oldBuffer.array(), oldBuffer.remaining());
And without flip()
Arrays.copyOf(oldBuffer.array(), oldBuffer.position());
, EJP, send(..), send() .